Skip to content

Instantly share code, notes, and snippets.

@Rafe
Rafe / gist:2091941
Created March 19, 2012 02:53
Ruby LOADPATH cheatsheet
#loadfile:
$:
$LOAD_PATH
require File.join(File.dirname(__FILE__), "foo", "bar") #=> "file/foo/bar"
#or
require File.expand_path(File.join(File.dirname(__FILE__), "foo", "bar"))
#=> "path/to/file/foo/bar"
require "foo/bar" #=> relative to loadpath, do this in relative files
@Rafe
Rafe / gist:2091680
Created March 19, 2012 02:44
RSpec Matcher helper:::
#true/false
target.should be
# can connect to every method that ends with ?
#ex :
target.should be_admin
# check target.admin?
target.should be_true
target.should be_false
def live_number(birthday)
reduce("#{birthday.year}#{birthday.month}#{birthday.day}")
end
def reduce(sum)
add_sum = each_digits(sum).reduce(:+)
add_sum >= 10 ? reduce(add_sum) : add_sum
end
def each_digits(num)
@Rafe
Rafe / phpspec.php
Created June 11, 2011 05:49
Custom php test framework
<?php
include_once dirname(__FILE__)."/../../config.php";
//use global varible to pass the success/false flag to prevent $this and return
//Assertion
static $testResult = true;
function should_be_true($value){
@Rafe
Rafe / gist:926434
Created April 18, 2011 22:46
html popout
<!DOCTYPE html>
<html>
<head>
<title>popout testing</title>
<style type="text/css">
#canvas{
height:412px;
width:915px;
background-image: url('canvas.jpg');
}
@Rafe
Rafe / hashWords.c
Created March 15, 2011 19:39
count words and saved in simple hash table
#include <stdio.h>
#include <string.h>
#include "zlib.h"
#define TABLE_SIZE 50000
struct _Word {
char *word;
uInt count;
};