July 1, 2015

No backlight on keyboard - Linux

I've recently purchased the CMSTORM Devastator which is a gaming combo (keyboard & mouse). The keyboard comes with a great red backlight that you can turn on/off by pressing the Scroll Lock button. In Windows it works right out of the box but not with Linux (I'm using Ubuntu).

To turn the keyboard's backlight on & off open a terminal and type the following:
xset led on
to turn on the backlight and
xset led off
to turn off the backlight.

Although the lights are now on you need to type the above commands each time you want to turn on/off the backlight which is not convenient. Hence I decided to write a small BASH script and point it to the Scroll Lock button. Start by creating an empty file using Gedit or any other text editing program. Now copy & paste the following:
#!/bin/bash

FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')

if [ "$FLAGS" = ffffe7fe ]; then

    xset led off

else

    xset led on

fi
Now save the file with the .sh extension. (I named it keyboard-led.sh) Move it in your root directory (or wherever you like) and make the script executable by typing (using a terminal):
chmod u+x keyboard-led.sh
Test the script by running:
./keyboard-led.sh
Now to make things simpler why don't we assign the script to a button in the keyboard? Open the keyboard settings and go to Custom Shortcuts. Then create a new shortcut. Give it a name and in the command section type /keyboard-led.sh. Finally click on the right of the shortcut and click the Scroll Lock button. Test if it works by pressing the Scroll Lock button.

Update 1: I noticed that in order to turn off the backlight I need to disable Num Lock or Caps Lock or both if they are enabled first (weird).
Update 2: The above problem is now fixed. Another problem remain though. When the backlight is on I can't use the Num Pad.

Now to the problem. What I did is I replaced the code in keyboard-led.sh with the code above:
#!/bin/bash

FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')

printf "$FLAGS""\n"
xset led on

FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')
printf "$FLAGS""\n"
and then I opened the terminal and I run /keyboard-led.sh 4 times.
The first time Num Lock and Caps Lock were disabled.
The output was ffffe7fc
The second time only Num Lock was enabled.
The output was ffffe7fd
The third time only Caps Lock was enabled.
The output was ffffe7fe
The fourth time both Nums Lock and Caps lock were enabled.
The output was ffffe7fe

Based on the outputs I created a condition that turns the backlight on & off even if Caps Lock or Num Lock or both are enabled. Replace the existing code in keyboard-led.sh with the code below.
#!/bin/bash

FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')

if [ "$FLAGS" = ffffe7fc ] || [ "$FLAGS" = ffffe7fd ] || [ "$FLAGS" = ffffe7fe ] || [ "$FLAGS" = ffffe7ff ]; then

    xset led off

else

    xset led on

fi
Update 3: Problem fixed. I noticed that when the backlight is on the Num Pad acts as a pointer controller (i.e. You can control the mouse pointer using the Num Pad). You can disable it through Universal Access -> Pointing and Clicking -> Control the pointer using the keypad.

June 28, 2015

Unable to format USB Flash Drive to full capacity

Today I decided to make a backup of some of my precious old stuff so I grabbed a 32GB flash drive that was laying around and plugged it in.

 I got the "format" message and then I remembered that a while back I installed a Live USB Linux distro. I went to Disk Management to format the flash drive and I noticed that there are 3 partitions on that drive. I formatted each partition hoping that this will remove the Linux distro and get my 32 GB back but now the flash drive shows as a 2 GB drive. In Disk Management it shows 2 partitions, both 2 GB and 25+ GB of unallocated space. I was hoping that I could delete these 2 partitions and but I couldn't do it using Disk Management. The solution (if you' re running Windows): If you run a Linux distro such as Ubuntu you can try formatting your flash drive using Disks (which is installed by default).

  1. Run Command Prompt (CMD)
  2. Type DISKPART
  3. Type LIST DISK This will list all available drives. Both internal and external.
  4. Type SELECT DISK # (# Replace with your disk number) Make sure you select the correct drive.
  5. Type LIST PARTITION This will return the available partitions in your drive.
  6. Type SELECT PARTITION 1
  7. Type DELETE PARTITION
  8. Type CREATE PARTITION PRIMARY to create a new full-sized partition.
  9. Type LIST PARTITION to confirm if the new partition is successfully created.
  10. Type EXIT
There are also a plethora of tools in the internet that can help but I don't usually trust them. If you used another method or tool to fix your USB flash drive comment about it below.

March 29, 2013

Install LAMP (Linux Apache MySQL PHP) & Drupal

PART 0 - DOWNLOAD DRUPAL
  1. Download the latest Drupal from here.
PART 1 - INSTALLING & CONFIGURE LAMP (Linux Apache MySQL PHP)
STEP 1 - Installing APACHE
  1. Open a terminal and type:
  2. sudo apt-get install apache2
  3. To make sure that Apache is installed open a web browser and type:
  4. http://localhost
  5. You should see something like this:
STEP 2 - Installing PHP
  1. Again open a terminal and type:
  2. sudo apt-get install php5 libapache2-mod-php5
  3. Now you must restart Apache:
  4. sudo /etc/init.d/apache2 restart
  5. To ensure that there are no issues with PHP run:
  6. sudo gedit /var/www/testphp.php
  7. A file called testphp.php will open.
  8. Copy and paste the following into the testphp.php
  9. 
    
  10. Save the file and exit
  11. Now open a web browser and type:
  12. http://localhost/testphp.php
  13. If it works then PHP is installed!
STEP 3 - Installing MySQL
  1. Open a terminal and type:
  2. sudo apt-get install mysql-server
  3. The above command will install MySQL
  4. Now comes the tricky part!
  5. Log in MySQL by typing:
  6. mysql -u root -p
  7. Now you need to set a password (Change yourpassword with the password you want. Do not remove ' '. Type your password between ' '.)
  8. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
  9. For example:
  10. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('12345');
  11. The next step is installing phpMyAdmin (A tool for editing your databases)
  12. sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
  13. Now you must edit the php.ini file in order to get PHP to work with MySQL
  14. gksudo gedit /etc/php5/apache2/php.ini
  15. Uncomment the following line by removing the semicolon (;)
  16. ;extension=mysql.so
  17. For example:
  18. extension=mysql.so
  19. Finally restart Apache:
  20. sudo /etc/init.d/apache2 restart
That's it your web server is up and running!
PART 2 - DRUPAL
  1. Open a terminal and type:
  2. sudo gedit /etc/apache2/apache2.conf
  3. apache2.conf will open
  4. In order for Drupal to functioning properly with Apache and PHP type the following at the the end of the file:
  5. AddType application/x-httpd-php.html
  6. Click Save
  7. Now it's time to create a Database
  8. Type the following and enter your password:
  9. mysql -u root -p
  10. To create a Database type:
  11. //Use whatever name you like instead of drupal
    CREATE DATABASE drupal;
  12. Now you need to create a user
  13. CREATE USER yourname@localhost;
  14. Finally define a password for the newly created user
  15. SET PASSWORD FOR yourname@localhost = PASSWORD('yourpassword');
  16. Now you need to grand permissions for the user
  17. GRANT ALL PRIVILEGES ON drupal.* TO yourname@localhost IDENTIFIED BY 'yourpassword'
  18. Go to the location that your Drupal was downloaded in PART 0 and unpack it
  19. Then copy the unpacked Drupal folder to /var/www/
  20. cp /home/user/Downloads/drupal-7.21 /var/www/
  21. Now head to /var/www/ and change directory to drupal
  22. cd drupal-7.21
  23. Change the permissions
  24. sudo chmod a+w sites/default
    cd sites/default
  25. Copy default.settings.php to settings.php
  26. cp default.settings.php settings.php
  27. Change the permissions
  28. sudo chmod a+w settings.php
  29. Finally create a directory named files
  30. sudo mkdir files
  31. and change permissions
  32. sudo chmod a+w files
  33. That's it!
  34. Now open a web browser and type:
  35. http://localhost/drupal-7.21
  36. Finally follow the on screen Drupal instructions to install Drupal

March 28, 2013

[HOW TO] Extract frames from video - Linux

To extract frames from a video do the following:

Install ffmpeg:

sudo apt-get install ffmpeg
Then decide how many frames you want to extract and do one of the following:

To extract each and every frame:

ffmpeg -i Video.mpg Pictures%d.jpg
For example:
ffmpeg -i /home/user/Desktop/Video.mpg Pictures%d.jpg
If you want to specify the number of frames to be extracted, the quality of the extracted frames or to start extracting from a particular point adjust your command by adding one of the following flags or all of them.
  • -r How many frames you want to be extracted per second (The default value is 25).
  • -f Defines the format.
  • Picture%3d.jpg %3d means that the names of the images will be like Picture001, Picture002 and so on. You can use any format you like.
  • -s You can define the image size.
  • -t You can set the duration of the extraction.
  • -vframes You can define how many frames you want to be extracted.
  • -ss Defines the time you want the extraction to start.
For example:
To extract 1 frame every second type:
ffmpeg -i Video.mpg -r 1 Picture%3d.jpg
To extract the frames from the first 10 seconds of the video type:
ffmpeg -i Video.mpg -t 10 Picture%3d.jpg
To start the extraction at a given time type: (for example: 0:34:14)
ffmpeg -i Video.mpg -ss 0:34:14 Picture%3d.jpg
To define the number of frames you want to be extracted type: (for example 80)
ffmpeg -i Video.mpg -vframes 80 Picture%3d.jpg
You can also be more specific by using all of the above flags together:
ffmpeg -i Video.mpg -r 2 -t 150 Picture%3d.jpg
The above command will extract 2 frames per second for 150 seconds.

March 24, 2013

[HOW TO] Install Guitar Pro - Linux Ubuntu 64bit

  1. Download the latest .deb from Guitar Pro's website.
  2. install ia32-libs by typing:
  3. sudo apt-get install ia32-libs
  4. Now you need to edit the .deb file to remove the gksu dependency.
    1. To do that you must create a script first.
      • To create the script open a terminal and type:
        vi debscript
      • This will create a new file named debscript.
      • debscript is just an example name. You can use whatever name you want.
      • Now type or copy/paste the following:
        #!/bin/bash
        
        if [[ -z "$1" ]]; then
          echo "Syntax: $0 debfile"
          exit 1
        fi
        
        DEBFILE="$1"
        TMPDIR=`mktemp -d /tmp/deb.XXXXXXXXXX` || exit 1
        OUTPUT=`basename "$DEBFILE" .deb`.modfied.deb
        
        if [[ -e "$OUTPUT" ]]; then
          echo "$OUTPUT exists."
          rm -r "$TMPDIR"
          exit 1
        fi
        
        dpkg-deb -x "$DEBFILE" "$TMPDIR"
        dpkg-deb --control "$DEBFILE" "$TMPDIR"/DEBIAN
        
        if [[ ! -e "$TMPDIR"/DEBIAN/control ]]; then
          echo DEBIAN/control not found.
        
          rm -r "$TMPDIR"
          exit 1
        fi
        
        CONTROL="$TMPDIR"/DEBIAN/control
        
        MOD=`stat -c "%y" "$CONTROL"`
        vi "$CONTROL"
        
        if [[ "$MOD" == `stat -c "%y" "$CONTROL"` ]]; then
          echo Not modfied.
        else
          echo Building new deb...
          dpkg -b "$TMPDIR" "$OUTPUT"
        fi
        
        rm -r "$TMPDIR"
      • Press Esc.
      • Now to save the file
        type :w
      • Finally to quit vi
        type :q
    2. Now its time to edit the .deb file.
    3. Move the script in the same folder as the Guitar Pro .deb file.
    4. You now need to make debscript executable.
    5. Open a terminal and type:
    6. chmod +x debscript
    7. Then type:
    8. debscript gp6-full-linux-r11201.deb
    9. Now delete gksu.
    10. To delete gksu move next to gksu and press x.
    11. To save the edited .deb file hit Esc and
    12. type :w
    13. Exit by
    14. typing :q
    15. A new file named gp6-full-linux-r11201.modfied.deb will be created.
    16. Do not close the terminal until the new .deb file is created.
  5. You can now install Guitar Pro 6.
  6. In the same terminal or in a new one type:
  7. sudo dpkg -i gp6-full-linux-r11201.modfied.deb
  8. That's it! Enjoy!

[HOW TO] Create a script - Linux

This tutorial will show you how to create a script in Linux. In this tutorial I am going to use vi. You can also use gedit or anything else if you want.
Open a terminal and type:
vi (name of the script)
For example "testscript". This will create a script named testscrip.
vi testscript
vi editor will open.
Now its time to start writing your script. Below is an example of a basic script that launches Firefox:
#!/bin/sh
echo “welcome”
firefox
Save your script by pressing Esc. Then:
Type :w
Quit vi by:
Typing :q 
Next type the command below to make the script executable:
chmod +x testscript
Finally to run the script type:
./testscript
That's it! Enjoy creating scripts!

March 22, 2013

[HOW TO] Install Cinnamon - Ubuntu/Fedora


To install the latest Cinnamon on your Linux Ubuntu/Fedora do the following:
  • Ubuntu
    • 12.04/12.10
Open the terminal and add the repository
sudo add-apt-repository ppa:gwendal-lebihan-dev/cinnamon-stable
Update the database
sudo apt-get update
Install Cinnamon
sudo apt-get install cinnamon
After the installation is complete log out and choose cinnamon.
    • 11.04/11.10
Open the terminal and add the repository
sudo add-apt-repository ppa:merlwiz79/cinnamon-ppa
Update the database
sudo apt-get update
Install Cinnamon
sudo apt-get install cinnamon
After the installation is complete log out and choose cinnamon.
  • Fedora
Before the cinnamon installation check if your system is up-to-date
Open the terminal
Once inside the terminal login as root
su --login
Check for updates
yum updates
Install Cinnamon
yum install cinnamon
After the installation is complete log out and choose cinnamon by clicking Session.

[HOW TO] Access files/folders with spaces - Linux

If you want to access a folder that has a name with a space for example the folder named New Folder do one of the following:
// If it's the only file/folder that starts with Ne

$ cd Ne*

// Or by using \ after each space

$ cd New\ Folder

// By using " "

$ cd "New Folder"

// By pressing Tab

$ cd (press tab)

October 25, 2012

[HOW TO] Fix Visual Studio 2012 .Net Framework error on Windows 8

If you are trying to install Visual Studio 2012 on Windows 8 Release Preview you might get the following error:

The .Net Framework installed on this machine does not meet the minimum required version: 4.5.50709.

In order to fix this error do the following:


Note: You will need to change the permissions before doing anything.

STEP 1 - CHANGE THE PERMISSIONS

  1. Navigate to C:\Windows and right click on regedit.exe
  2. Click Properties
  3. Go to Security Tab and click Advanced button.
  4. Click Change (next to Owner)
  5. In the textbox right Administrators and click OK
  6. Click Apply and OK
  7. From the users list select Administrators and click Edit.
  8. Check Full Control and click OK
  9. Click OK 
STEP 2 - REGEDIT
  1. Run regedit.exe
  2.  For 64-bit Windows go to the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full
  3.  For 32-bit Windows: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
  4. Right click on the "Full" folder and select Permissions.
  5. Go to Advanced
  6. Click Change
  7. In the textbox type Administrators
  8. Click OK
  9. Select Administrators
  10. Check Full Control
  11. Click OK
  12. Change the value for "Version" to "4.5.50709"
You should now be able to install Visual Studio 2012