Posts tagged howto

Setup plugins directory in Linux (debian) for Firefox

I had issues with Firefox not finding the plugins for flash. I had to setup the following environment variable for it to find it:

Check if it is already set:

echo $MOZ_PLUGIN_PATH

If it is not, set it:

export MOZ_PLUGIN_PATH=/home/user/.mozilla/plugins

Any path will work, I just used the .mozilla directory to keep things clean.

You should restart Firefox to see the plugins.

 

This was tested on Debian Wheezy.

Recover MySQL root password on Linux and Windows

It happens that sometimes (after 2 days ūüôā ) you forget the password for your root user on MySQL, well there are few steps to perform to recover it.

This was performed on version:

$ mysql -V
mysql  Ver 14.14 Distrib 5.1.61, for debian-linux-gnu (x86_64) using readline 6.2

The following steps need to be performed as root user, so either login with it or use sudo.

Step 1:Stop the MySQL service

$ sudo /etc/init.d/mysql stop

Step 2: Start the MySQL server without password

$ sudo mysqld_safe --skip-grant-tables &

Step 3: Connect to the MySQL server using the MySQL client

$ sudo mysql -u root

Step 4: Change the password for the root user

mysql> use mysql;
Database changed
mysql> update user set password=PASSWORD("YOUR_NEW_PASS") where user = 'root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

Step 5: Stop the MySQL server again

$ sudo /etc/init.d/mysql stop

Step 6: Start the MySQL server (normally) and test the new password

$ sudo /etc/init.d/mysql start
$ sudo mysql -u root -p

 

This should also work on Windows as well, you will just need to use different commands for start/stop of the MySQL deamon.

 

 

Making rounded corners in GIMP

I bugged myself a little to create an image in GIMP which will have rounded corners. I tried with selection tools and everything else I could think of to no avail. Then I browsed trough the Filters selections and I found the script Round Corners. The image I created was initially like this (you can also import a picture):

Looks kinda dull and boring, so now we will make it with round edges and make it more interesting ūüôā

Click on the Filters -> Decor -> Round Corners… and a new window with settings will be shown.

NOTE: if the filter Round Corners is grayed-out and you cannot select it, it means that the image has Alpha channel, so you need to remove that. Go to Layer -> Transparency -> Remove Alpha Channel

The window with the settings should look like this

The default settings might not work for everybody, so you can test it how it transforms and what you need.

The options are pretty much self explanatory, so for example if you do not want any shadows just set the Shadow X/Y offset to 0, Work on copy will create a new file and will not modify the original, Add Background will put the new image on a background etc.

The default settings will generate an image like this

You can see the rounded edges, the shadow, the blur on the shadow and the background (white). Now the image looks much slicker and more modern.

Let me know if you have questions about this in the comments below.

Add multiple language support for your Android application independent of the phone global settings

There is a way to create a multiple language application in Android and let the user choose which language to use on application level. This is very positive because not everybody wants to use the application on the system level language or they do not have a phone in their language. So the following is a way to implement application level language settings. This excerpt is used in the application when the Menu button is pressed, it will show all the options you need plus the language selection. After the language is selected, the application will restart itself in the new language.

Code snippet:

case 112: //Language Select
dialog = new Dialog(MainActivity.this);
  dialog.setContentView(R.layout.langselect);
  dialog.setCancelable(true);

  dialog.setTitle(R.string.sChooseLang);

     Button butBack = (Button) dialog.findViewById(R.id.backButton);

     butBack.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
             dialog.dismiss();
         }
     });

 hmLocales = new HashMap<String, String>();
 hmLocales.put(getString(R.string.sMacedonian), "mk"); // Macedonian
 hmLocales.put(getString(R.string.sAlbanian), "sq"); // Albanian
 hmLocales.put(getString(R.string.sEnglish), "en"); // English
 hmLocales.put(getString(R.string.sSerbian), "sr"); // Serbian
 hmLocales.put(getString(R.string.sFrench), "fr"); // French

 lvLangs = (ListView) dialog.findViewById(R.id.lvLanguages);
 String sLanguages[] = this.getResources().getStringArray(R.array.saLanguages);
 lvLangs.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , sLanguages));                        

 dialog.show();

 lvLangs.setOnItemClickListener(new OnItemClickListener() {
    //@Override
    public void onItemClick(AdapterView<?> a, View v, int position, long id) {
        String t = (String) lvLangs.getItemAtPosition(position);
        String sLocale = hmLocales.get(t);

        MyApplication.updateLanguage(getApplicationContext(), sLocale);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        dialog.dismiss();
    }
 });

 

After you have finished coding, you will need to create new folders for the translated strings based on the country/language codes that you have in your application. Based on the example above there should be  res/values, res/values-en, res/values-sq, res/values-fr and res/values-sr folders. There is no res/values-mk because the Macedonian translation would be the default and therefore it is stored in res/values. Note that the country/language codes on the folders need to match the ones in the code.

You are all set! Now get busy and translate the strings ūüôā

In another post I will talk how to store the language value permanently (unless the user changes it) so that it will not reset to default on every restart of the application.

How to move your WordPress to a new domain name

As you might have noticed, there is a new domain name for this blog. Now the domain is http://redoem.com It is easier to remember and shorter than the previous one (http://blog.zasekoj.com).

The whole process took approximately 45 minutes, but yours could vary depending on the amount of posts, comments, images etc that you have.

NOTE: this is not for blogs hosted on wordpress.com. For them many of the steps will be different, but you can try and adapt the following.

OK, enough chit-chat, let’s get to work. First of all, of course, you need to buy a new domain name (I am using DreamHost – you can register as well for hosting and use coupon REDOEM30 to get 1 extra FREE lifetime domain registration and $30 off your total amount!).

  1. Create a new user in your panel (if the hosting does not do it automatically) which will have FTP access to your domain name.
  2. Remove all the junk that you do not need like spam comments pending, drafts you are not planning to use, themes that you don’t need etc. This takes additional space and there is no need to transfer it across different databases.
  3. Disable all the WordPress plugins and empty cache if you are using caching plugin
  4. Export your database
    • Login to your MySQL server (phpMyAdmin) and click on the Export tab
    • Select your database on the left of the screen (do not select the Information_Scheme database)
    • All of the settings by default should be OK, unless you are advanced user and you know what you are doing and what else you might need
    • Go to the bottom of the page and click the check box that says Save as file
    • Enter a template for your filename (the default is OK)
    • Leave the Compression set to None. It will cut few steps later
    • Click the Go button on the bottom-right and save the file to your disk
  5. Open the saved export file in a text editor which supports Find and Replace (like Notepad++, TextMate, GEdit etc)
  6. Find and replace all of the instances where your old domain name is used. NOTE: start with the longest string, for example db.olddomain.com would be replaced with db.newdomain.com, then go on to the lower lever by replacing olddomain.com to newdomain.com, and last just the domain name from olddomain to newdomain. Please be careful with this last one because it could change some of the things that you don’t want to be changed. I recommend to check which instances are they and either replace them one by one where needed or use extra filters. For example when I was doing this last bit I used /home/olddomain/ to /home/newdomain/ because that worked for me, see if such options will work for you too.
  7. If you want to change the database name, at the top of the file there should be a statement like “CREATE DATABASE namehere ….” change the name to whatever you want. Please note that later you will need this name.
  8. Save the file
  9. Login to your new MySQL Server (phpMyAdmin) for the new domain.
  10. Click Import and select the file that you modified. Click OK
  11. When the import is complete, you will receive a message stating that, if there are errors you will be informed as well. Now we will assume that it was successful.
  12. Login via (S)FTP to your olddomain where the WordPress installation is currently located
  13. Copy all the files (the wp-include, wp-content and wp-admin folders as well) from olddomain.com to your local disk (recommended) or directly to the newdomain (usually via SSH)
  14. Open the file wp-config.php in a text editor and modify the following fields:
    • define(‘DB_NAME’, ‘newdatabase’);¬† — this is the name from step 7
    • define(‘DB_USER’, ‘newdatabaseuser’);¬†¬† — this is the user that you use to connect to the database/phpMyAdmin
    • define(‘DB_PASSWORD’, ‘newdbpass’);¬† — this is the password that you use to connect to the database/phpMyAdmin
    • define(‘DB_HOST’, ‘db.newdomain.com’);¬† — this is the hostname for the new database
  15. Transfer all the files to the newdomain.com folder
  16. Try to open the newdomain.com site — it should open successfully
  17. Reactivate all the plugins that you had previously, or the ones that you want one. Some of them might need to be re-configured to work on the new domain (SEO, Google Sitemap etc)
  18. Change any custom code that you have, like Google Analytics, Adwords etc
  19. Create a new file called .htaccess(note the dot at the beginning and no extension) for permanent redirect from the old site to the new site. This is important so that you don’t lose any traffic. However if you are losing the olddomain.com you cannot do this. Enter the following in it:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://newdomain.com/$1 [R=301,L]
  20. Place the newly created file .htaccess inside the olddomain.com directory
  21. Remove all the files inside the olddomain.com directory (EXCEPT the .htaccess file that you added in step 20)
  22. Try the old site and see if the redirect works properly

Well, that was it. After all of these steps your WordPress installation should be moved to the new domain name and everything should stay the same. The redirect is very important (step 19) so make sure you keep your old domain for at least several more months after the move so that all the old traffic is redirected successfully. You can omit this step if you have a new site with very few visits, but then again I guess you can just create a new WordPress installation and do not perform the above steps ūüôā

Enjoy and let me know in the comments if you have any problems.

 

Disable “Restart Now” on automatic updates in Windows

If you have setup your Windows machine to perform automatic updates, when a new update is available it will nag you with a popup message to restart your computer so that the updates can be applied.

There are several ways to disable or post-pone this from annoying you every 10 minutes (default setting).

  1. Disable the Automatic Updates Service for the current session, meaning it will not show up this message until the computer is restarted. Note that this will be reset after the restart so you will need to repeat it again next time when you have new updates to be applied. To disable the automatic updates for the current session type the following in the Run screen in Windows (Start -> Run):
    sc stop wuauserv

  2. Modify the group policy settings so the time between message popup is greater than the default value. Open the Group Policy Settings by entering gpedit.msc in Start -> Run. On the screen that will open, go to the following location:
    Local Computer Policy

    Computer Configuration
    Administrative Templates
    Windows Components
    Windows Update


    Now, locate the Re-prompt for restart with schedule installations option in the list and double click on it.

    Set it is as Enabled and change the waiting period to 1440 minutes (maximum value == 1 day). Enjoy the uninterrupted work! ūüôā

Note: Option 2 works only on Windows XP Professional and not on Windows XP Home. However, option 1 works for all versions of Windows XP. These options were not tested on Windows 7, but they might work there as well.

Change Network Card MAC in Ubuntu/Linux

A Media Access Control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment. Read more about MAC addresses here.

Tip: Please write down your current MAC address before you continue

To change the MAC address in Ubuntu, perform the following:

Temporary solution

  1. Open terminal and check your current MAC address:
    ifconfig |grep HWaddr  

    Output should be something like this (MAC’s are red):
    eth0           Link encap:Ethernet  HWaddr f4:6d:0b:37:f9:83
    vboxnet0  Link encap:Ethernet  HWaddr 0b:00:23:00:00:00
    wlan0       Link encap:Ethernet  HWaddr e0:c9:d5:1a:ed:b5

  2. Now, disable the network interface (eth0 for the wired network connection, wlan0 for wireless etc.):
    sudo ifconfig eth0 down
     

     

  3. Change the MAC address:
    sudo ifconfig eth0 hw ether 00:15:a5:d5:39:19
     

  4. Enable the network interface:
    sudo ifconfig eth0 up
     

  5. Check if the change is successful:
    ifconfig |grep HWaddr  

    Should return the changed address:
    eth0           Link encap:Ethernet  HWaddr 00:15:a5:d5:39:19
    vboxnet0  Link encap:Ethernet  HWaddr 0b:00:23:00:00:00
    wlan0       Link encap:Ethernet  HWaddr e0:c9:d5:1a:ed:b5

Permanent solution

  1. Open the interfaces file, you can choose any text editor you want:
    sudo vi /etc/network/interfaces  

    You should see something like the following:
    auto lo
    iface lo inet loopback

  2. Add this line at the bottom of the file:
    hwaddress ether 00:15:a5:d5:39:19 

    The red text is the MAC address, so replace this one with your desired address.

  3. Restart the networking service or your computer:
    sudo /etc/init.d/networking restart

Common issue(es)

  1. If there is no connectivity after ifconfig eth0 up or sudo /etc/init.d/networking restart try the following:
    dhclient eth0 

    This will request a new IP address and it should fix the connectivity issue.

Go to Top