Use CodeIgniter ActiveRecord library outside of your website February 15, 2011 No Comments
If you ever find yourself in a situation where you need, or want, to use the CodeIgniter ActiveRecord library outside of your website, for example a cron script that does some periodic data manipulation, here is an easy way to do it.
get('offers');
foreach ($offers->result_array() as $offer)
{
print_r($offer);
}
?>
Keep your SSH session alive May 31, 2010 No Comments
There is a nice option called ServerAliveInterval in ssh that keeps your session alive when left idle. It takes one parameter, number of seconds to send a keep alive packet to the server to make it look like the session is active.
You can use it in two ways
First, you can pass it as a parameter to the ssh client
ssh -o ServerAliveInterval=240 user@domain
Second, you can add it to /etc/ssh/ssh_config, for global configuration, or ~/.ssh/config, for user configuration
ServerAliveInterval 240
Shell script progress update February 22, 2010 No Comments
If you are writing shell scripts that manipulate big amounts of data it is helpful to the person running the script to know what is going on.
The easies way is to just print out a status line every now and then. The problem is when we have a lot of status updates with just a small change we end up with a full screen of status updates but with very little useful data.
For example, we have a list of cities that we are updating and we would like to know how far along are we.
We could print a bunch of lines like this
Updating cities: loaded 10000 Updating cities: loaded 20000 Updating cities: loaded 30000 Updating cities: loaded 40000 ..
But it would be a lot nicer if we just have the number changing.
The solutions for this is to print the new status update over the existing one. You would do that by printing Carriage Return character in front of the status update so it just overwrites the previous one.
In Bash it looks like this
# Bash printf "Update cities: loaded 10000" # some code printf "\rUpdate cities: loaded 20000" #...
If you happen to write a shell script in PHP or Perl it would look like this
// PHP echo "\r Updating cities: loaded 10000"; // some code echo "\r Updating cities: loaded 20000";
# Perl printf "Update cities: loaded 10000"; # some code printf "\rUpdate cities: loaded 20000";
Creating .POT files June 30, 2009 No Comments
copied from http://codex.wordpress.org/User:Skippy/Creating_POT_Files
- Start POEdit
- Click File -> New Catalog
- Enter a project name (probably your plugin’s file name)
- Click the Paths tab at the top
- Click the New Item icon (second one, looks like a little square)
- Enter the path to the directory containing your plugin file (“.” tells POEdit to scan the directory that you will save the file to), press enter
- Click the Keywords tab at the top
- Click the New Item icon
- Enter __ (that’s underscore underscore), press enter
- Click the New Item icon
- Enter _e (that’s underscore e), press enter
- Click Okay
- Choose a name for your .po file (probably your plugin’s base filename)
The Update Summary window should display, with a list of strings that were found to translate, based on the keywords supplied above (__ and _e). Click Okay.
Save the .po file, and exit the program.
Make the .po file available for download (or optionally include it in the plugin archive). Translators will use this file to construct a .mo file, which will be used by the load_plugin_textdomain() function.
Return to previous revision on SVN June 24, 2009 No Comments
svn up -r PREV filename
SVN – Check what will be updated on ‘svn up’ June 22, 2009 No Comments
Very usefull when more than one people work on a piece of code
svn st -u
PHP one-liners May 26, 2009 No Comments
I spend a lot of time in the command line, and one of the most usefull thinks for me is the PHP CLI(Command Line Interface).
You can write and execute PHP scripts and application just as you would do with Perl or Python. And more importantly, you can write one-liners scripts.
For example, if you want to rotate an image for 180 degrees, you can do it with this one line
php -r '$img = imagecreatefromjpeg($argv[1]); $rotate = imagerotate($img, 180, 0); imagejpeg($rotate, basename($argv[1],".jpg")."_rotated.jpg");' my_image.jpg
jQuery checkbox check May 15, 2009 No Comments
It’s quite easy to check if the checkbox is checked
if ($("#my_checkbox").is(':checked'))
{
// do stuff
}
Javascript global variables March 18, 2009 No Comments
There are two ways to define global variables in JavaScript. Actually, there might be more, but I’ve used these two.
First, you can define a variable without the ‘var’ keyword and it will be accessible in the functions.
globalVar = 'test';
function doSmthng(){
var localVar = globalVar + 'ing';
}
The other way is to declare global variable with ‘var’ keyword, in which case it is accessible through the window object
var globalVar = 'test';
function doSmthng(){
var localVar = window.globalVar + 'ing';
}
Load and execute .sql file March 11, 2009 No Comments
//copied from php.net, autor: sb at stephenbrooks dot org
function load_db_dump($file,$sqlserver,$user,$pass,$dest_db ) {
$sql=mysql_connect($sqlserver,$user,$pass);
mysql_select_db($dest_db);
$a=file($file);
foreach ($a as $n => $l) if (substr($l,0,2)=='--' || substr($l,0,2)=='##') unset($a[$n]);
$a=explode(";\n",implode("\n",$a));
unset($a[count($a)-1]);
foreach ($a as $q) if ($q)
if (!mysql_query($q)) {echo "Fail on '$q'"; mysql_close($sql); return 0;}
mysql_close($sql);
return 1;
}