Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
jehoshua02 / ValueHelper.php
Created January 8, 2013 04:22
Cuz we love seeing "Notice: Undefined index: ..." SOOOOO much!
<?php
class ValueHelper
{
/**
* Construct method
*
* @param mixed $value
*/
public function __construct($value)
@jehoshua02
jehoshua02 / counting.php
Last active December 11, 2015 05:29
Counting in ruby and php.
<?php
function countBy($x = 1, $to = 100)
{
return range(0, $to, $x);
}
function countOccuranceOf($value, $array)
{
$counts = array_count_values($array);
@jehoshua02
jehoshua02 / tc_is_a_vs_instance_of.rb
Last active December 11, 2015 05:38
Difference between `is_a?` and `instance_of?`
require 'test/unit'
class TestInstanceOf < Test::Unit::TestCase
def test_string_is_a_string
assert "string".is_a? String
end
def test_string_instance_of_string
assert "string".instance_of? String
@jehoshua02
jehoshua02 / NoCrupht_Router.php
Created January 26, 2013 20:15
Demonstrating possible Router usage ...
<?php
namespace NoCrupht;
class Router
{
/**
* Holds array of routes
*
* @var array
@jehoshua02
jehoshua02 / sqlph.php
Created January 29, 2013 00:29
Just playing around with a PHP SQL library idea ...
<?php
// get a user
$user = Sqlph::select('user')
->where('username')->equals($username)
->and('password')->equals($password)
->limit(1)
->fetch();
echo sprintf('Hello, %s!', $user->username); // access this way?
###################################################
# WHITELISTED FILES
#
# Because we found so much garbage in here
# that we cannot tell what is important, and
# because we don't want to track garbage, we
# have the `include_log.php` script automatically
# append included files here.
#
# DO NOT EDIT BELOW -- Put custom .gitignores above
@jehoshua02
jehoshua02 / func_bitmask_decompose.php
Last active December 12, 2015 08:59
Decompose PHP error reporting level. I see uncommented error reporting integers in my apache configs and have a hard time knowing what they mean.
<?php
/**
* Decomposes a bitmask value into bitmask components
*
* @param int $value The bitmask value to decompose
* @param array $bitmasks An array of possible bitmask components
*
* @return array
*/
@jehoshua02
jehoshua02 / Database.php
Created February 11, 2013 08:39
Simple database class wrapped around a MySQL PDO object.
<?php
/**
* Database
*
* Simple database class wrapped around MySQL PDO object
*/
class Database
{
/**
@jehoshua02
jehoshua02 / function.dump.php
Last active December 13, 2015 19:18
Sometimes it's annoying to try to find those var_dump()'s
<?php
/**
* Dumps a value with the file and line number where dump was called
*
* @params mixed $value Value to dump
* @params mixed $dumpFunction The function name or closure used to dump the value. Default to var_dump()
*/
function dump($value, $dumpFunction = 'var_dump') {
$trace = array_shift(debug_backtrace());
@jehoshua02
jehoshua02 / Color.php
Last active December 14, 2015 17:08
Try it: `git clone https://gist.github.com/5119903.git Color; php Color/usage.php | less -R`
<?php
class Color
{
protected static $fgColors = array(
'black' => "\033[0;30m",
'darkGray' => "\033[1;30m",
'red' => "\033[0;31m",
'lightRed' => "\033[1;31m",
'green' => "\033[0;32m",