This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.
29 05, 2009

explode

By | 2009-10-15T22:42:12+00:00 May 29th, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on explode

The explode function takes 2 parameters – the first is the delimiter, and the second is the string to be exploded. It returns an array of strings, each of which is a substring of the original, formed by splitting the original string on boundaries formed by the string delimiter.

PHP

$my_string = 'perl, python, java';
$array = explode(', ', $my_string);
var_dump($a);
/*
Array (
	[0] => perl
	[1] => python
	[2] => java
)
*/

Ruby

my_string = 'perl, python, java';
puts my_string.split(', ');
# => ["perl", "python", "java"]
26 05, 2009

shuffle

By | 2009-05-21T16:29:35+00:00 May 26th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on shuffle

Randomizes the order of the elements in an array.

PHP

$a = array('a', 'b', 'c', 'd');
shuffle($a);
print_r($a);
/*
Array (
	[0] => d
	[1] => b
	[2] => c
	[3] => a
)
*/

Ruby

a = [ "a", "b", "c", "d" ];
puts a.sort_by{ rand };
# => ["d", "b", "c", "a"]
23 05, 2009

str_pad

By | 2009-05-20T13:27:13+00:00 May 23rd, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on str_pad

str_pad allows a string to be added to a particular length using another string.

PHP

echo str_pad('Hi', 5);
// => 'Hi   '

echo str_pad('Hi', 5, '+');
// => 'Hi+++'

echo str_pad('78', 5, '0', STR_PAD_LEFT);
// => '00078'

Instead of padding a string, in Ruby we justify a string to the left or right.

Ruby

puts "Hi".ljust(5);
# => 'Hi   '

puts "Hi".ljust(5, '+');
# => 'Hi+++'

puts "78".rjust(5, '0');
# => '00078'

To pad both sides of a string, we need to use a combination of ljust and rjust.

PHP

echo str_pad('Special', 11, '*', STR_PAD_BOTH);
// => '**Special**'

Ruby

puts "Special".ljust(9).rjust(11);
# => '**Special**'
20 05, 2009

time

By | 2009-05-19T15:04:00+00:00 May 20th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on time

Returns the current Unix timestamp (epoch).

PHP

echo time();
// => 1242744141

Ruby

puts Time.now.to_i;
# => 1242744141
17 05, 2009

microtime

By | 2009-05-19T14:48:01+00:00 May 17th, 2009|Categories: PHP, Ruby|Tags: , , , , |1 Comment

Returns the current Unix timestamp (epoch) with microseconds.

PHP

echo microtime();
// => 0.63928794 1242744141

Ruby

epoch_mirco = Time.now.to_f;
epoch_full = Time.now.to_i;

epoch_fraction = epoch_mirco - epoch_full;

puts epoch_fraction.to_s + ' ' + epoch_full.to_s;
# => 0.639287948608398 1242744141
14 05, 2009

md5_file

By | 2009-05-15T23:21:33+00:00 May 14th, 2009|Categories: PHP, Ruby|Tags: , , , , , , |Comments Off on md5_file

The md5_file() function calculates the md5 hash of a file.

PHP

$my_file = '/home/ali/article.txt';

echo md5_file($my_file);

// => 745d3dfb68af1b1384aea0125aae5c3f

MD5 encryption can be done using the Digest::MD5 class in Ruby, but to generate a hash for a file, we need to read it’s contents into a variable (string) first.

Ruby

require 'digest/md5';

my_string = File.read('/home/ali/article.txt');

print Digest::MD5.hexdigest(my_string);

# => 745d3dfb68af1b1384aea0125aae5c3f
11 05, 2009

sha1_file

By | 2009-05-15T23:12:59+00:00 May 11th, 2009|Categories: PHP, Ruby|Tags: , , , , , , |Comments Off on sha1_file

The sha1_file() function calculates the sha1 hash of a file.

PHP

$my_file = '/home/ali/article.txt';

echo sha1_file($my_file);

// => bef6b2b56f70eb6f2c250e00c855f4c0120832aa

Sha1 encryption can be done using the Digest::SHA1 class in Ruby, but to generate a hash for a file, we need to read it’s contents into a variable (string) first.

Ruby

require 'digest/sha1';

my_string = File.read('/home/ali/article.txt');

print Digest::SHA1.hexdigest(my_string);

# => bef6b2b56f70eb6f2c250e00c855f4c0120832aa
8 05, 2009

sha1

By | 2009-05-15T23:22:14+00:00 May 8th, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on sha1

The sha1() function calculates the sha1 hash of a string.

PHP

echo sha1('apple');
// => d0be2dc421be4fcd0172e5afceea3970e2f3d940

Sha1 encryption can be done using the Digest::SHA1 class in Ruby. To use this class, we need to require the Digest library first…

Ruby

require 'digest/sha1';

print Digest::SHA1.hexdigest('apple');

# => d0be2dc421be4fcd0172e5afceea3970e2f3d940
5 05, 2009

md5

By | 2009-05-15T23:22:33+00:00 May 5th, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on md5

The md5() function calculates the md5 hash of a string.

PHP

echo md5('apple');
// => 1f3870be274f6c49b3e31a0c6728957f

MD5 encryption can be done using the Digest library in Ruby. To use the Digest library, just require it…

Ruby

require 'digest/md5';

print Digest::MD5.hexdigest('apple');

# => 1f3870be274f6c49b3e31a0c6728957f
2 05, 2009

error_log

By | 2009-05-15T23:15:05+00:00 May 2nd, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on error_log

The error_log() function sends an error message to the web server’s error log, a TCP port or to a file (usually the web server’s error log).

PHP

error_log('My error message');
// => My error message

error_log() is probably one of the most common and convenient ways to debug PHP scripts, without having to install a full PHP debugger. As such, it is very popular with developers, often logging variables part way through a script, to see if the values are what they expect. Although Ruby doesn’t provide such a convenient global function, it does provide the Logger class which is much more powerful.

Ruby

require('Logger');
Logger.new('/var/log/httpd/error.log').error('My error message');
# => ERROR -- : My error message