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 07, 2009

is_float

By | 2009-08-11T15:11:24+00:00 July 29th, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on is_float

The is_float() function allows you to check if a particular variable is a float (type).

PHP

$number = 6.5;
var_dump( is_float($number) );
// => true

Ruby

number = 6.5;
puts number.is_a?(Float);
# => true
26 07, 2009

range

By | 2009-08-10T08:45:56+00:00 July 26th, 2009|Categories: PHP, Ruby|Tags: , |Comments Off on range

The range() function creates an array containing a range of elements in PHP, however in Ruby the Range object is used to handle ranges of integers or strings.

PHP

$chars = range('a', 'c');
print_r($chars);
// => array(0 => 'a', 1 => 'b', 2 => 'c')

Ruby

chars = 'a'..'c'
chars.each {|item| print "#{item}, " } 
# => a, b, c,
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"]
20 07, 2009

array_push

By | 2009-10-15T22:41:12+00:00 July 20th, 2009|Categories: PHP, Ruby|Tags: , , |Comments Off on array_push

The array_push() function pushes elements onto the end of an array (acting in the opposite way to array_pop).

PHP

$programming = array('java', 'ruby', 'python', 'php');
array_push($programming, 'asp');
print_r($programming);
=> /* 
Array
(
    [0] => java
    [1] => ruby
    [2] => python
    [3] => php
    [4] => asp
)
*/

Ruby

programming = ['java', 'ruby', 'python', 'php'];
programming.push('asp');
=> # ["java", "ruby", "python", "php", "asp"]
17 07, 2009

array_pop

By | 2009-10-15T22:41:20+00:00 July 17th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on array_pop

The array_pop() function removes the element off the end of an array and returns it’s value.

PHP

$my_array = array('java', 'ruby', 'python', 'php');
echo array_pop($my_array);
=> // php

Ruby

my_array = ['java', 'ruby', 'python', 'php'];
puts my_array.pop
=> # php
13 07, 2009

ucwords

By | 2009-08-03T16:17:16+00:00 July 13th, 2009|Categories: PHP, Ruby|Tags: , , , , , |1 Comment

The ucwords() function turns the first character of each word in a string to upper-case, if the first character is alphabetic.

PHP

echo ucwords("ruby is easy.");
=> // Ruby Is Easy. 

Ruby doesn’t have a function which can capitalize all the words in a string – so to accomplish this it’s a little bit harder. You need to split the string into words, then capitalize the first character of each word, and then finally join all the words back into a string.

Ruby

puts "ruby is easy.".split(' ').select {|w| w.capitalize! || w }.join(' ');
=> # Ruby Is Easy. 
10 07, 2009

lcfirst

By | 2009-08-03T14:11:57+00:00 July 10th, 2009|Categories: PHP, Ruby|Tags: , , , , , |2 Comments

The lcfirst() function returns a string, with the first character in lower case – only if the first character is alphabetic.

PHP

echo lcfirst("Java is OK.");
=> // java is OK.

Ruby

my_string = "Java is OK.";

puts my_string[0,1].downcase + my_string[1..-1];
=> # java is OK.
7 07, 2009

ucfirst

By | 2009-08-03T13:54:38+00:00 July 7th, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on ucfirst

The ucfirst function returns a string, with the first character capitalized – only if the first character is alphabetic.

PHP

echo ucfirst("ruby is great!");
=> // Ruby is great! 

Ruby

puts "ruby is great!".capitalize
=> # Ruby is great!