Skip to content

Instantly share code, notes, and snippets.

@jamierumbelow
jamierumbelow / montyhall.rb
Created April 12, 2013 14:03
Monty Hall problem
~/Sites/bits ᐅ ruby montyhall.rb
Runs: 1000000
Sticking wins: 33.3413%
Switching wins: 66.6587%
@jamierumbelow
jamierumbelow / search_model.php
Created April 10, 2013 22:02
A quick multi-table multi-field search model for CI / PHP
<?php
class Search_model extends CI_Model
{
protected $tables = array(
'users' => array( 'name', 'email' )
);
public function run($search)
{
@jamierumbelow
jamierumbelow / committee.json
Created January 22, 2013 08:52
Fetch a JSON array of select committees
{
"Business, Innovation and Skills Select Committee (overseeing the operations of the Department for Business, Innovation and Skills and related bodies)": {
"members": [
{
"member": "Adrian Bailey MP (Chair)",
"member_chair": true,
"party": "Labour Co-op"
},
{
"member": "Brian Binley MP",
<?php
for ($i = 1; $i < 101; $i++)
{
if (($i % 3) == 0)
{
$line = "Fizz";
}
elseif (($i % 5) == 0)
{
@jamierumbelow
jamierumbelow / composer.json
Created November 19, 2012 19:50
Installing PHPUnit via Composer
{
"require": {
"phpunit/phpunit": "3.7.*"
}
}
@jamierumbelow
jamierumbelow / user_controller_test.php
Created October 13, 2012 13:42
Testing for Laravel 4
<?php
namespace App\Tests\Unit;
use App\Models\User as User;
class UserControllerTest extends \PHPUnit_Framework_TestCase
{
public function testMostPopular()
{
@jamierumbelow
jamierumbelow / gist:3702259
Created September 11, 2012 21:38
Something stupidly cool in Ruby
def search id
Model.find id
rescue => e
log "Error in search: #{e.message}"
end
<?php
$mongo.prototype.extend(
{
public function get($collection)
{
this.prototype._find({ collectionName: $collection });
}
});
$ ruby popularity_test.rb
Loaded suite popularity_test
Started
.
Finished in 0.000979 seconds.
1 tests, 4 assertions, 0 failures, 0 errors, 0 skips
@jamierumbelow
jamierumbelow / gist:2519816
Created April 28, 2012 15:28
JavaScript's .split() being stupid
# Let's say we have an email message body with some headers and then the email
# content. Just like HTTP, headers\n\nbody
string = "Header: here\n\nHere is an email\n\nwith some line breaks\n\nand stuff"
# What you'd expect (what PHP's explode() does)
string.split("\n\n", 2) == [ "Header: here", "Here is an email\n\nwith some line breaks\n\nand stuff" ] # false
# What you actually get
string.split("\n\n", 2) == [ "Header: here", "Here is an email" ] # true