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.
11 11, 2010

array_fill_keys

By | 2010-11-11T13:02:39+00:00 November 11th, 2010|Categories: PHP, Ruby|Tags: , , , |1 Comment

The array_fill_keys() function in PHP allows you to populate the values of an array while specifying its keys.

PHP

$keys = array('write', 'debug', 'execute');
$result = array_fill_keys($keys, 'code');
var_export($result);
// => array('write' => 'code', 'debug' => 'code', 'execute' => 'code')

To replicate this functionality in Ruby, we need to use a Hash object, since arrays in Ruby don’t use associative key/value pairs.

Ruby

keys = ['write', 'debug', 'execute']
result = keys.inject({}) do |hash, key| 
  hash[key] = 'code'
  hash 
end
p result
# => {"write"=>"code", "debug"=>"code", "execute"=>"code"}
13 10, 2010

array_fill

By | 2010-10-13T11:17:44+00:00 October 13th, 2010|Categories: PHP, Ruby|Tags: , , , , , |1 Comment

The array_fill() function in PHP allows an array to be populated (i.e. filled) with a particular value.

PHP

$a = array_fill(3, 5, 'php');
print_r($a);
/*
Array (
	[3] => php
	[4] => php
	[5] => php
	[6] => php
	[7] => php
)
*/

In Ruby this is not really possible because Ruby arrays must have their keys filled in the correct order, i.e. you cant skip assigning values to keys in a Ruby array. As such, the next best thing is to fill those values with nil, or use a hash instead.

Ruby

a = [nil] * 3 + ['php'] * 5;
puts a;
# => [nil, nil, nil, 'php', 'php', 'php', 'php', 'php']
10 10, 2009

array_unique

By | 2009-10-19T08:55:30+00:00 October 10th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on array_unique

The array_unique() function in PHP takes an array and filters our any duplicates values, returning the array with only unique values present.

PHP

$elements = array('php', 'ruby', 'perl', 'php');
array_unique($elements);
print_r($elements);
/*
Array (
	[0] => php
	[1] => ruby
	[2] => perl
)
*/

Ruby

elements = [ "php", "ruby", "perl", "php" ];
puts elements.uniq;
# => ["php", "ruby", "perl"]
4 10, 2009

array_values

By | 2009-10-15T22:35:54+00:00 October 4th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on array_values

The array_values() function in PHP takes an array and returns all it’s values as a numeric array.

PHP

$array = array('go' => 'green', 'stop' => 'red');
var_dump( array_values($array) );
/*
Array (
	[0] => green
	[1] => red
)
*/

To replicate this functionality in Ruby, we need to use a Hash object, since arrays in Ruby don’t use associative key/value pairs.

Ruby

array = { :go => 'green', :stop => 'red' };
puts array.values;
# => ["green", "red"]
1 10, 2009

list

By | 2009-10-15T22:36:18+00:00 October 1st, 2009|Categories: PHP, Ruby|Tags: , , , , , , |Comments Off on list

The list() function in PHP is used to assign multiple variables as if they were an array. Technically, list() is not a function in PHP, it is a language construct.

Ruby has no real need for a function such as list(), as the same can be achieve using parallel assignment – i.e. assigning comma separated variables to elements of an array using the normal assignment operator.

PHP

$langs = array('php', 'ruby', 'perl');
list($lang1, $lang2, $lang3) = $langs;
echo $lang1;	// php
echo $lang2;	// ruby
echo $lang3;	// perl

Ruby

langs = [ "php", "ruby", "perl" ];
lang1, lang2, lang3 = langs;
puts lang1;	# php
puts lang2;	# ruby
puts lang3;	# perl
23 07, 2009

array_combine

By | 2009-10-15T22:41:01+00:00 July 23rd, 2009|Categories: PHP, Ruby|Tags: , , , , , |3 Comments

The array_combine() function creates an associative array (hash) by using one array for keys and another for values.

PHP

$a = array('python', 'lisp', 'perl');
$b = array('PY', 'LI', 'PE');
$c = array_combine($a, $b);

print_r($c);
=> /* 
Array
(
    [python] => PY
    [lisp] => LI
    [perl] => PE
)
*/

To replicate this functionality in Ruby, we need to use a Hash object, since arrays in Ruby don’t use associative key/value pairs.

Since there is no exact equivalent of to the array_combine() function in Ruby, we manually create a hash from two different arrays.

Ruby

p1 = ['python', 'lisp', 'perl'];
p2 = ['PY', 'LI', 'PE'];

# initialize the hash
combined_hash = {}

# build the hash from 2 different arrays
p2.each_with_index do |val, key| 
  combined_hash[p1[key]] = val
end

# print resulting hash
p combined_hash
=> # ["python"=>"PY", "lisp"=>"LI", "perl"=>"PE"]