IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Blog
C#

Getting data from Dapper result

Dapper query result returns DapperRow collections: IEnumerable<dynamic>{List<Dapper.SqlMapper.DapperRow>}. In order to use the data inside DapperRow object, we need to convert the data into usable types. Get single value var data = conn.ExecuteScalar("select top 1 title from book"); string title = $"{data}"; int id = conn.ExecuteScalar<int>("select top 1 id from book"); Get data from a single row var row = conn.QuerySingle("select top 1 title, url_target from book"); var title = $"{row.title}"; Get data as a Array: var data = conn.Query("select title, url from book").Select(x => x.title).ToArray(); foreach(var d in data){ string title = d; } Get data as a List: var data = conn.Query("select title, url from book").Select(x => x.title).ToList(); foreach(var d in data){ string title = d; } Get data as a Dictionary: var data = conn.Query("select title, url from book").ToDictionary(row => (string)row.title, row => (string)row.url); foreach(var k in data.Keys){ string key = k; string value = data[k]; } Get data as an object: var books = conn.Query<Book>("select * from book"); //returns IEnumerable<Book> foreach(var book in books){ string title = book.Title; } Dapper automatically mapped the column data to the fields in the object by their names.  610 total views,  5 views today

2022-08-12 0 Comments 122 Views 0 Like IT Team Read more
Security

How to block bad bots in Appache server

Nowadays more and more web crawlers visit a website, some are good for you, such as google search engine, they respect robots.txt protocol. But some of them have bad behavior that has negatively impact to your site. How to block the bad bots These crawlers are called bot. A bot is a software program that operates on the Internet and performs repetitive tasks. While some bot traffic is from good bots, bad bots can have a huge negative impact on a website or application. So we want to block those bad bots from visiting our site. Normally, we can set rule in robots.txt file, but the bad bots do not respect these rules. So setting up robots.txt file is only for good bots. To be sure the bad bots are blocked, we have to use .htaccess file. Here are the steps: 1. find out the bot keyword from the user-agent from the log. 2. add the following script to the top of .htaccess file: a) set rewrite condition: It uses regular expression to match multiple user agents in one line. RewriteEngine On RewriteCond %{HTTP_USER_AGENT} "dataforseobot|Yandex|AhrefsBot|BLEXBot|SemrushBot" [NC] RewriteRule "^.*$" - [F,L] Or b) using SetEnvIf directives: SetEnvIfNoCase User-Agent "AhrefsBot" badbots SetEnvIfNoCase User-Agent "BLEXBot" badbots SetEnvIfNoCase User-Agent "SemrushBot" badbots SetEnvIfNoCase User-Agent "YandexBot" badbots SetEnvIfNoCase User-Agent "dataforseobot" badbots <Limit GET POST HEAD>  Order Allow,Deny  Deny from env=badbots </Limit> Both scripts are equiverant, just pick the one you like. By using the script above the page will return 403 (forbidden) to the bad bots. Test the effects Here's an example that uses chrome browser…

2022-01-06 0 Comments 499 Views 5 Like IT Team Read more
Plugin

Add ALT attribute to Social Media Icon

AlT attribute for an image is helpful factor for SEO. But the plugin "Social Media Share Buttons" by Sygnoos is not adding alt attribute for all social images. The following is my approach to add alt attribute to the social images. For this reason, Bing search console is always give a warning message and refuse to index the site. 1. Find possible keyword using browser tool. 2. locate keyword using Visual Studio find feature. Location: /wp-content/plugins/social-media-builder/js/addNewSection/SGMBWidget.js 3. add alt attribute to the images with jQuery. 4. result: Additionary, to set all images ALT value where alt is missing, using this script: Set alt value to image file name where alt is missing $('img').each(function(i,e){ if($(e).attr('alt')=='') $(e).attr('alt', $(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,'')); }); How to get this script? Explained below. //show all img src $('img').each(function(i,e){console.log($(e).attr('src'));}); //show all img alt $('img').each(function(i,e){console.log($(e).attr('alt'));}); //get file name from path filepath.replace(/^.*(\\|\/|\:)/, ''); //get file name without extension from file name filename.replace(/\.[^/.]+$/,''); //show all img file name without extension $('img').each(function(i,e){console.log($(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));}); //set alt value to image file name where alt is missing $('img').each(function(i,e){if($(e).attr('alt')=='') $(e).attr('alt', $(e).attr('src').replace(/^.*(\\|\/|\:)/, '').replace(/\.[^/.]+$/,''));});    1,002 total views,  3 views today

2021-12-03 0 Comments 338 Views 5 Like IT Team Read more
Wordpress

Change Event Calendar Title

Background Info Theme: OceanWP Plugin: The Event Calendar Solution Event Calendar title in header bar is renderred by theme OceanWP in file: /themes/oceanwp/partials/function oceanwp_title(). The title is get by function oceanwp_title() in file: /themes/oceanwp/inc/helpers.php. In order to override the tile, we created a new file functions-events.php with the following code: if ( ! function_exists( 'oceanwp_title' ) ) {     function oceanwp_title() {         ... //copy code here from theme and insert the following code         if( tribe_is_month() && !is_tax() ) { // Month View Page             $title = esc_html__( 'Metro\'s Event Schedule', 'oceanwp' );         }         elseif( tribe_is_month() && is_tax() ) { // Month View Category Page             //echo 'Metros Event Schedule category page';         }         // Last check if title is empty         $title = $title ? $title : get_the_title();         // Apply filters and return title         return apply_filters( 'ocean_title', $title );     } } In functions.php add include file statement: require_once('functions-events.php' ); Note: Translate Wrap string with function esc_html__() in order to retrieve the translation of the new string. Translate with Loco plugin. First the pot file need to be updated. Make sure the new string is shown in the file. Edit translate file, use Sync button to update the content strings. Result  1,835 total views,  5 views today

2021-11-09 0 Comments 363 Views 3 Like IT Team Read more
HTML

Emojis and icons for HTML

Emojis 😀 &#128512; 😁 &#128513; 😂 &#128514; 😃 &#128515; 😄 &#128516; 😅 &#128517; 😆 &#128518; 😇 &#128519; 😈 &#128520; 😉 &#128521; 😊 &#128522; 😋 &#128523; 😌 &#128524; 😍 &#128525; 😎 &#128526; 😏 &#128527; 😐 &#128528; 😑 &#128529; 😒 &#128530; 😓 &#128531; 😔 &#128532; 😕 &#128533; 😖 &#128534; 😗 &#128535; 😘 &#128536; 😙 &#128537; 😚 &#128538; 😛 &#128539; 😜 &#128540; 😝 &#128541; 😞 &#128542; 😟 &#128543; 😠 &#128544; 😡 &#128545; 😢 &#128546; 😣 &#128547; 😤 &#128548; 😥 &#128549; 😦 &#128550; 😧 &#128551; 😨 &#128552; 😩 &#128553; 😪 &#128554; 😫 &#128555; 😬 &#128556; 😭 &#128557; 😮 &#128558; 😯 &#128559; 😰 &#128560; 😱 &#128561; 😲 &#128562; 😳 &#128563; 😴 &#128564; 😵 &#128565; 😶 &#128566; 😷 &#128567; 😸 &#128568; 😹 &#128569; 😺 &#128570; 😻 &#128571; 😼 &#128572; 😽 &#128573; 😾 &#128574; 😿 &#128575; 🙀 &#128576; 🙁 &#128577; 🙂 &#128578; 🙃 &#128579; 🙄 &#128580; 🙅 &#128581; 🙆 &#128582; 🙇 &#128583; 🙈 &#128584; 🙉 &#128585; 🙊 &#128586; 🙋 &#128587; 🙌 &#128588; 🙍 &#128589; 🙎 &#128590; 🙏 &#128591; 🤐 &#129296; 🤑 &#129297; 🤒 &#129298; 🤓 &#129299; 🤔 &#129300; 🤕 &#129301; 🤖 &#129302; 🤗 &#129303; 🤞 &#129310; 🤟 &#129311; 🤠 &#129312; 🤡 &#129313; 🤢 &#129314; 🤣 &#129315; 🤤 &#129316; 🤥 &#129317; 🤦 &#129318; 🤧 &#129319; 🤨 &#129320; 🤩 &#129321; 🤪 &#129322; 🤫 &#129323; 🤬 &#129324; 🤭 &#129325; 🤮 &#129326; 🤯 &#129327; 🤰 &#129328; 🤱 &#129329; 🤲 &#129330; 🤳 &#129331; 🤴 &#129332; 🤵 &#129333; 🤶 &#129334; 🤷 &#129335; 🤸 &#129336; 🤹 &#129337; 🤺 &#129338; 🤼 &#129340; 🤽 &#129341; 🤾 &#129342; 🥂 &#129346; 🧐 &#129488; 🧑 &#129489; 🧒 &#129490; 🧓 &#129491; 🧔 &#129492; 🧕 &#129493; 🧖 &#129494; 🧗 &#129495; 🧘…

2021-05-24 0 Comments 544 Views 0 Like IT Team Read more
HTML

Special characters and symbols for HTML

Usage To express: yóu, type the HTML entity like: y&oacute;u. Chinese PinYin(a e i o u) ā &#257; á &aacute; ǎ &#462; à &agrave; ē &#275; é &eacute; ě &#283; è &egrave; ī &#299; í &iacute; ǐ &#464; ì &igrave; ō &#333; ó &oacute; ǒ &#466; ò &ograve; ū &#363; ú &uacute; ǔ &#468; ù &ugrave; ǖ &#470; ǘ &#472; ǚ &#474; ǜ &#476; Greek characters Α &Alpha; &#913; Β &Beta; &#914; Γ &Gamma; &#915; Δ &Delta; &#916; Ε &Epsilon; &#917; Ζ &Zeta; &#918; Η &Eta; &#919; Θ &Theta; &#920; Ι &Iota; &#921; Κ &Kappa; &#922; Λ &Lambda; &#923; Μ &Mu; &#924; Ν &Nu; &#925; Ξ &Xi; &#926; Ο &Omicron; &#927; Π &Pi; &#928; Ρ &Rho; &#929; Σ &Sigma; &#931; Τ &Tau; &#932; Υ &Upsilon; &#933; Φ &Phi; &#934; Χ &Chi; &#935; Ψ &Psi; &#936; Ω &Omega; &#937; α &alpha; &#945; β &beta; &#946; γ &gamma; &#947; δ &delta; &#948; ε &epsilon; &#949; ζ &zeta; &#950; η &eta; &#951; θ &theta; &#952; ι &iota; &#953; κ &kappa; &#954; λ &lambda; &#923; μ &mu; &#956; ν &nu; &#925; ξ &xi; &#958; ο &omicron; &#959; π &pi; &#960; ρ &rho; &#961; ς &sigmaf; &#962; σ &sigma; &#963; τ &tau; &#964; υ &upsilon; &#965; φ &phi; &#966; χ &chi; &#967; ψ &psi; &#968; ω &omega; &#969; ϑ &thetasym; &#977; ϒ &upsih; &#978; ϖ &piv; &#982; Currency Symbols ¢ &cent; &#162; £ &pound; &#163; ¤ &curren; ¥ &yen; &#165; € &euro; &#8364; ₠ &#8352; ₰ &#8368; ₳ &#8371; Math Symbols ° &deg; &#176; ¹ &sup1; ² &sup2; ³ &sup3; < &lt; &#60; ≤ &le;…

2021-05-24 0 Comments 521 Views 1 Like IT Team Read more
Wordpress

Fixing Kratos theme multi-language issue

This is a note for fixing Kratos theme multi-language issue. Basic information Theme: Kratos Language plugins: Polylang, Loco Language settings: en_CA, zh_CN Symptom On English version, always display Chinese words. While OceanWP theme displays correctly for multi-languages. Reason The theme offers multi-language support for American English, Japanese, and Chinese language files: en_US, ja_JP, zh_TW. For English only contains en_US, not en_CA. For multi-language use, I created a en_CA language file under common location: /wp-content/languages/themes/kratos-en_CA.po. In the theme, the language file location is locked on theme directory.  Therefore all other languages that located on other location cannot be found. function theme_languages() { load_theme_textdomain('kratos', get_template_directory() . '/languages'); } add_action('after_setup_theme', 'theme_languages'); Fixing multi-language issue As a quick fix, just change en_CA to en_US, instead of creating another language file. Then it displays as expected. For better solution, the en_CA language file could be copied over to theme language directory, in order to keep Canadian English style.  1,873 total views

2021-03-17 0 Comments 663 Views 4 Like IT Team Read more
Wordpress

Controling Category List on Sidebar Widget

Category list on sidebar widget will display all categories on post category hierarchy by default. However, we do not want to display all of them for some reason. Here is simple technique to achieve this goal. Find category IDs First thing to do is to find out all category IDs that we don't want them to show on the sidebar. Run the following script against WordPress MySQL database. SELECT t.term_id catID,t.name FROM wp_terms t join wp_term_taxonomy tax on tax.term_id=t.term_id where tax.taxonomy='category' Snippets //Hide categories from WordPress category widget function exclude_widget_categories($args){ $exclude = "4,6,7,8,9,10,13,14,15,16"; $args["exclude"] = $exclude; return $args; } add_filter("widget_categories_args","exclude_widget_categories"); Apply the snippets There are many ways to apply the snippets. You could add it to theme functions.php file or using snippets plugin to apply the snippets code. In my case, I'm using snippets to apply the code. This way is better organized for reusing the snippets. Last words, This is the simplest way to contorl the category list on sidebar, but you may use other ways to control the category list on sidebar, for instance, find a proper plugin or write your own plugin to achieve it.  9,490 total views,  3 views today

2021-03-04 2 Comments 3331 Views 1 Like IT Team Read more
Wordpress

Restoring the Links Manager

WordPress Links Manager is a tool to manage a set of links. You can add, modify, and remove a link easily from admin dashboard. By default, WordPress come with a widget to add a sidebar, where the links will be shown. The Links Manager is provided by default in earlier versions of WordPress than Version 3.5. However, the WordPress Links Manager and blogroll are hidden for new installs. Moreover, if you used an earlier version than 3.5 and upgraded your installation, then the Links Manager was removed if you don’t have any links. Restoring the Links Manager 1. Using filter Add the following line to your theme’s functions.php file to enable WordPress Links Manager if you are using WordPress version 3.5 or higher To enable Links Manager in version 3.5+, just add the following code to one of the following locations: functions.php file of the theme; php snippets plugin; your own plugin; add_filter( 'pre_option_link_manager_enabled', '__return_true' ); Once enabled, you can see a Links tag in the left panel of the dashboard. 2. Change option value from database If you can access the database you could enable it pritty easy by changing the option value in the database directly. There is an option_name = 'link_manager_enabled' in wp_options table. You can set this value to 1 directly. update wp_options set option_value=1 where option_name='link_manager_enabled'; What Link Manager plugin does is just to change this value in wp_option table behind the scene using filter function. Displaying Links in sidebar WordPress provides a widget within its Links Manager. So you can easily locate links in the sidebar…

2021-02-08 0 Comments 583 Views 1 Like IT Team Read more
Wordpress

Scheduling Background Job in WordPress

There are many things have to be done on background, for instance, version check, update theme, delete posts, delayed posting, delete transients, etc. In WordPress this background job is performed by WP-Cron, witch is defined in wp-cron.php file. WordPress cron is the system built-in process that handles the scheduling of time-based tasks. Out-of-the-box, WordPress performs a number of scheduled tasks, they include: WordPress core update checks Plugin update checks Theme update checks Publishing of scheduled posts WP-Cron takes its name from cron, which is a time-based job scheduler in Unix-like systems. However, WP-Cron is designed to work on any hosting provider (including shared hosting) without using any external software or tools for scheduling events. Problem of WP-Cron The wp-cron.php is triggered on every http request. If any scheduled event is due, the event is spawned to wp-cron.php for processing, so the event is triggered to run. This is unreliable, espectially for low traffic sites, or heavily cached sites, cause scheduled events to be missed if no traffic is received for a prolonged period of time. For high-traffic sites, WP-Cron is extremely inefficient. This is because WP-Cron will check for scheduled events on every page load. This could mean that the cron schedules are being checked multiple times per second. This is unnecessary and highly redundant, as scheduled events typically run in minutes or hourly, even monthly interval. Even wp-cron.php creates a lock in WordPress transient, witch stored in wp_options table, but for high traffice sites the high concurrent requests may still spawn multiple requests to wp-cron.php, thus increasing server load.…

2021-02-07 1 Comments 4183 Views 2 Like IT Team Read more
12345
Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
WP UI Design - Language Selection on Menu Bar Emojis and icons for HTML Change contact form 7 field display size Generating Test Data with SQL Scripts WordPress EventCalendar visibility Add activity log for WordPress
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com