OpenVPN in ArchLinux on a OpenVZ VPS

So after struggling for hours trying to get OpenVPN working and routing traffic correctly, I finally managed to get it working.

Step 1: Follow the guide at https://wiki.archlinux.org/index.php/OpenVPN
Step 2: Instead of running

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

run

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j SNAT --to (venet0 ip)

This should correctly route traffic using the venet0 interface.

Batch Install APKs

Copy .apk files to any folder in sdcard, for example “new-apps”
Type these following commands in console:

  1. adb shell
  2. su
  3. cd /sdcard/new-apps
  4. for app in *.apk; do pm install -r $app; done

PHP/MySQL: Conditional Update column in Multiple Records

This PHP function generates a SQL query that updates a single column in multiple records with different values based on a list of conditions. Executing a single UPDATE query for a small number of records may be okay but for a large number of records, it may seriously affect the performance of your script/application. Here’s a way to quickly update a column in multiple records using a single query. This method is tested for updating 10,000+ records and it has worked without a hiccup so far.

Basic syntax for updating multiple records using a list of conditions:

  1. UPDATE `table_name` SET `column_1` = CASE `condition`
  2. WHEN 1 THEN ’1st value’
  3. WHEN 2 THEN ’2nd value’
  4. END
  5. WHERE `condition` IN (1, 2);

PHP function to generate multi update query:

  1. function make_multi_query( $table_name, $column_name, $condition_name, $condition_values ) {
  2.   $query = "UPDATE `" . $table_name . "` SET `" . $column_name . "` = CASE `" . $condition_name . "`";
  3.     foreach($condition_values as $id => $value) {
  4.       $query .= " WHEN ‘" . $id . "’ THEN ‘" . $value . "’";
  5.     }
  6.   $query .= " END WHERE `" . $condition_name . "` IN (‘" . implode( "’,'" , array_keys( $condition_values ) ) . "’ );";
  7.   return $query;
  8. }

PHP function example usage:

  1. $table_name = "users";
  2. $column_name = "active";
  3. $condition_name = "username";
  4. $condition_values = array("user1" => "Y", "user2" => "N");
  5. echo make_multi_query($table_name, $column_name, $condition_name, $condition_values);

Above example will return the following query:

  1. UPDATE `users`
  2. SET `active` = CASE `username`
  3. WHEN ‘user1′ THEN ‘Y’
  4. WHEN ‘user2′ THEN ‘N’
  5. END
  6. WHERE `username` IN (‘user1′,‘user2′ );

Linux/Kubuntu Nvidia Driver

Manual Nvidia driver install instructions: http://ubuntuforums.org/showthread.php?t=1467074

Additional Note: Remove xserver-xorg-video-nouveau before starting install.

UDP Chat in Python

Very basic UDP chat.

For Point-to-Point, enter IP and Port

For Broadcasting mode set the last byte of IP address to 255. i.e. 192.168.0.255

Port number is HEX, remove the base 16 to make it decimal. Continue reading “UDP Chat in Python” »