Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Hasselbring mikelbring

View GitHub Profile
View leak.php
<?php
// Will this cause a memory leak?
// Will a new instance of ObjectClass stay in memory each iteration?
// If I attach it to a variable will it replace the old memory pointer?
foreach ($a as $k) {
new ObjectClass($k);
}
View gist:5058786
class LearnMyABCs
def initialize
@letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
end
def speak(text)
puts text
system 'say ' + text
end
View gist:2364079
<?php
class Date {
/**
* Convert a local timestamp to a GMT timestamp.
*
* @static
*
* @param string $timestamp
* @param string $timezone
* @param string $format
@mikelbring
mikelbring / hack.sh
Created Mar 31, 2012 — forked from erikh/hack.sh
OSX For Hackers
View hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
View gist:2174664
<?php
//Here we're setting BIT_0, BIT_1, ..., BIT_15 for use with octal notation
//It's basically saving 1,2,4,8,16, ..., 32768 to prevent possible typos and less calculations
// 2^n = BIT_n
$t = 1;
for ($i = 0; $i < 16; $i++) {
define('BIT_' . $i, $t);
$t <<= 1;
}
View gist:2158826
<?php
$post = Post::find(1);
$post->comments()->insert(array(
'body' => $body,
'author' => $author
));
View gist:2158811
<?php
$post = Post::find(1);
$comment = new Comment();
$comment->fill(array(
'post_id' => $post->id,
'body' => $body,
'author' => $author
View gist:2158805
<?php
class Post extends Eloquent {
public static $table = 'posts';
public function comments()
{
return $this->has_many('Comment');
}
View _IDE_HELPER.php
<?php
class Auth extends System\Auth { }
class Benchmark extends System\Benchmark { }
class Cache extends System\Cache { }
class Config extends System\Config { }
class Cookie extends System\Cookie { }
class Crypt extends System\Crypt { }
class DB extends System\DB { }
class Error extends System\Error { }