Posted on Leave a comment

How To Filter Non Alphanumerics Characters From Your String And Its Application In Excel

How To Filter Non Alphanumerics Characters From Your String And Its Application In Excel 1

If you are like me, I have to deal with text a lot in my work. As a programmer, I need to find and match string. Recently, a friend of mine, who is an accountant gave me a list of books’ titles. Most of them are fine. However, there are some contains strange characters and she wanted to remove such titles.

How To Filter Non Alphanumerics Characters From Your String And Its Application In Excel 2

As you can see in the picture, there titles with @ and Chinese characters. Using filters doesn’t work because there are more than 1000 rows. That was when I said to myself: “I need a tool”.

So, I made one for this specific purpose: “to help my friend remove all the strange characters in her Excel workbook”.

Here is how the tool look like:

How To Filter Non Alphanumerics Characters From Your String And Its Application In Excel 3

As you can see, you can put the original text in the source string box, adjust a few options above and click on filter. The result will be shown in the Result string box:

How To Filter Non Alphanumerics Characters From Your String And Its Application In Excel 4

As you can see that all the rows that contain strange characters are removed.

However, what if you have some special characters that is allowed to appear in the title? No worries! You can put that into the Allowed characters box and separated them by spaces.

For example, It is OK for me to have the character @ in the title, I would put @ into the Allowed characters box. In addition, that title [email protected] contains the character dot (.) so you need to put that into the list of allowed characters too.

Let’s see what we’ll have:

How To Filter Non Alphanumerics Characters From Your String And Its Application In Excel 5

As you can see now, the title with . and @ is accepted.

There are also two checkboxes that allowed you to filter the text further. You can decide to allow numbers or spaces in the title by checking these checkboxes.

I put the full source code for the tool here:

https://github.com/datmt/Remove-Lines-Contain-NonAlphaNumeric-Characters

If you are not a programmer, you can download the application here to start using it:

Download the .jar file

If you have any suggestions, please let me know. Thank you very much!

Posted on Leave a comment

How To Fix “Fatal Error: Allowed memory size of … bytes exhausted” In WordPress

How To Fix "Fatal Error: Allowed memory size of ... bytes exhausted" In WordPress 6

Setting up your WordPress blog is easy. With an affordable hosting, you can have you site up in just a few minutes. When you first start out, your site may have little traffic and it runs smoothly. However, when your site get popular and you get more traffic, you may encounter this message when you open your site:

How To Fix "Fatal Error: Allowed memory size of ... bytes exhausted" In WordPress 7

You cannot view your beautiful site anymore and so as your visitors. What is the cause and what can you do to fix it?

What is the cause of Allowed memory size of … bytes exhausted?

As the error message suggests, your WordPress site has used up all the allowed memory. For example, your server settings allocated 32MB for your site to run. However, due to high amount of traffic to your site, it used up all the 32MB. Thus, there is no more memory left for your site to continue running. That’s the reason why you see that message.

How to fix this problem?

As you can see, the cause is lack of memory so the fix should be to increase the amount of allowed memory for WordPress to run. It sounds very simple, however, it is not always the case.

Why so?

The reason is this problem usually occurs on cheap hosting, where the hosting providers usually allocate a small amount of RAM for their users. You must ask your hosting provider to increase the allowed memory for your WordPress site. If they don’t agree to do so, you are out of luck.

However, in case they agree to increase your memory limit, you can do the following steps to give your site more memory to run.

  1. Going to your site by using cPanel/FTP/SSH
  2. Open wp-config.php
  3. Put this line:

define( ‘WP_MEMORY_LIMIT’, ’64M’ );

right above the part says: /* That’s all, stop editing! Happy blogging. */

You can replace the number 64 to a higher one if allowed. For a blog that gets a lot of traffic, you may need to set the limit to 512M or even more.

Then, save the wp-config.php file and you are done. Your WordPress site now have more memory to operate. Make sure to monitor your site closely to see if you still have this error. If you still get this error, you can increase the limit once again. In case the memory limit that your hosting provider gives you is low, you should consider upgrading your hosting plan to a VPS.

 

Posted on Leave a comment

How To Add New Currency To WooCommerce

How To Add New Currency To WooCommerce 8

Woocommerce comes with quite many currencies. In fact, if you are selling items internationally, you got a plenty of options to choose from such as USD, GBP, EUR or even BTC (bitcoin). However, there are a lot of currencies isn’t in that list. For example, what if you want to accept ETH (Ethereum) as your currency? Don’t worry, we can make that work.

Check if your currency is supported by Woocommerce

Woocomemerce is updated frequently. Thus, chances are your currency get added in the latest release. The first thing you need to do is to:

  1. Update Woocommerce to the latest version
  2. Go to Woocommerce->Settings->General->Scroll to the bottom to see the currency options. You can see the list of supported currencies there

If your desired currency is in the list, that’s great! You don’t need to do anything else. If it isn’t, read on.

Introducing the necessary hooks

If you are unfamiliar with the term hooks, you can take a look at the official document here. However, it is not necessary to understand it thoroughly to add new currencies to Woocommerce.

There are two filter hooks you need to use to add new currency to Woocommerce

  1. woocommerce_currencies
  2. woocommerce_currency_symbol

As the names suggest, the first one will be used to register new currency and the second one will be used to register the currency’s symbol.

The actual code

I’m going to register the Ethereum currency to Woocommerce. However, you can define and add any type of currency you want. You can even invent a currency that isn’t available right now.

add_filter( 'woocommerce_currencies', 'bc_add_new_currency' );
add_filter( 'woocommerce_currency_symbol', 'bc_add_new_currency_symbol', 10, 2 );

function bc_add_new_currency( $currencies ) {
     $currencies['ETH'] = __( 'Ethereum', 'your-theme-text-domain' );
     return $currencies;
}


function bc_add_new_currency_symbol( $symbol, $currency ) {
     
     if( $currency == 'ETH' ) {
          $symbol = '♦';
     }
     return $symbol;
}

There are a few places in the code above you need to pay attention to:

  1. The symbol of ETH is ♦. You can replace this with your currency’s symbol .
  2. Name of your currency. In the code, it is “Ethereum”. You can change this to the name of your currency. For example: Bitcoin Cash
  3. The index key ‘ETH’. This can be anything but unique across all currencies.

Now, after you modify the code to match your currency of choice, put it at the end of the functions.php file in your active theme folder:

How To Add New Currency To WooCommerce 9

The result

Now, if you go to Woocommerce->Settings->General and scroll down to Currency Options, you can search for the new currency:

How To Add New Currency To WooCommerce 10

That’s it! That’s how you can add new currencies to Woocommerce. You can add as many new currencies as you want, there is no limit.

Posted on Leave a comment

How To Resize and Copy Images Files To Android Drawable Folders Quickly

I’m not a full time Android developer. I make Android apps such as this. Android studio is great and I can develop my ideas quickly. However, there is one thing I don’t like is the way I have to deal with images. Every time I need to add an icon to my app, I need to resize that image to the following sizes:

  1. 144 x 144
  2. 96 x 96
  3. 72 x 72
  4. 48 x48

And put them in the following folders, respectively:

  1. drawable-xxhdpi
  2. drawable-xhdpi
  3. drawable-hdpi
  4. drawable-mdpi

The task is boring and tedious. So, I decided to make a tool to make this task less painful.

How does the tool work?

Let’s say you want to use a new icon like this in your app:

How To Resize and Copy Images Files To Android Drawable Folders Quickly 11

Now, instead of resize and copy the file 4 times, you just need to open the tool:

How To Resize and Copy Images Files To Android Drawable Folders Quickly 12

The first step is to select your /res folder which contains the drawable-..dpi folders. The Directory Chooser will make this step simple an easy.

Now, look at the checkboxes, they are self-explanatory. If for some reasons, you don’t want to copy the image to a particular folder, simply uncheck the checkbox in front of it.

Then, click on select Image to select your image. The image should be square and have resolution at lest 144 x 144 pixel to avoid pixelation.

If your image is in JPG format, you select JPG, if it is PNG, select PNG.

How To Resize and Copy Images Files To Android Drawable Folders Quickly 13

After that, you click on open to complete the process.

And that’s all. You don’t need to open your image editor to resize the images. With less time spent, you have your images in all drawable folders.

Further features

I made this tool out of my need. I think there are more improvements to be made. Here are some ideas:

  • Let user set the resolution (instead of fixed size as of now)
  • Let user select more folders, even add folders outside the /res folder

The app is free and the repo is open on github. You can download the source and the app here

I hope the app can save you some precious time. Let me know if you have any suggestions.

 

Posted on Leave a comment

How To Find Big Images That Makes Your Site Load Slowly

Images is one of the biggest reasons why sites take a very long time to load. I should say big image to be exact. Some website owners are not aware of this fact and they still upload big images to their website and set the size smaller by using width and height attribute. A classic example is you use your images from a digital camera (or your phone) and upload directly to your website without scaling it down first. The images could be a few MB to over ten MB in size. This is a big problem if you know that in order for a web page to load fast, its total size should not exceed a few MB (except you own a gallery site).

How to find big images in your web pages

Fortunately, finding big images in your web pages is very simple with browser’s tools. You can use any browser to find big images. However, I would recommend you use Google Chrome for the ease of use.

Step 1: Navigate to the URL you want to inspect

In this example, I go to a post in my local site which writes about tiger:

How To Find Big Images That Makes Your Site Load Slowly 14

Step 2: Right click any where on the post and select inspect

How To Find Big Images That Makes Your Site Load Slowly 15

You will see the console panel appears. Click on Network tab:

How To Find Big Images That Makes Your Site Load Slowly 16

Step 3: Reload your page

You will see a new panel appears listing all request your make to the web server.

How To Find Big Images That Makes Your Site Load Slowly 17

Step 4: Click on the size tab to sort the request in size order

How To Find Big Images That Makes Your Site Load Slowly 18

As you can see, the image is the biggest resource listed at the top.

How do you avoid using big images in your posts

Images is an indispensable part of your content. Without images, your site will look boring and your visitors may not return the second time. However, uploading big images can cause a strain on users’ precious data limit (especially when they use 3G connection). The obvious solution is to resize the image before uploading. Doing so not only help you serve smaller images but also save your server storage. However, this task is tedious, especially when you have to upload many pages for your posts.

A better solution for WordPress users

If you use WordPress, the solution is very simple. WordPress allow you to set the size of the images after you upload.

When uploading images, you notice this section after the image is uploaded:

How To Find Big Images That Makes Your Site Load Slowly 19

You can see that we can select sizes for the image. In this case, my picture has the original resolution is 2560 x 858 pixel, which is very large (both in dimensions and in size ). However, I see that if the image is 640 x 214, my visitors can view the details just fine and it saves me a huge amount of bandwidth. So, I choose this option.

Conclusion

Many of us have the luxury of unlimited connection, fast wi-fi… However, there are many people access the internet with limited data plan. Reducing your images size can reduce the time your visitors have to wait on your site and also their cost on mobile data. Your site will also load faster and your visitors will be more happy.