Skip to content

Instantly share code, notes, and snippets.

View mikelbring's full-sized avatar

Michael Hasselbring mikelbring

View GitHub Profile
<?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);
}
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
<?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 March 31, 2012 14:48 — forked from erikh/hack.sh
OSX For Hackers
#!/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
#
<?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;
}
<?php
$post = Post::find(1);
$post->comments()->insert(array(
'body' => $body,
'author' => $author
));
<?php
$post = Post::find(1);
$comment = new Comment();
$comment->fill(array(
'post_id' => $post->id,
'body' => $body,
'author' => $author
<?php
class Post extends Eloquent {
public static $table = 'posts';
public function comments()
{
return $this->has_many('Comment');
}
@mikelbring
mikelbring / _IDE_HELPER.php
Created June 13, 2011 17:07
Laravel IDE Helper
<?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 { }