This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# irb(main):001:0> h = {} | |
# => {} | |
# irb(main):002:0> h.foo = "bar" | |
# => "bar" | |
# irb(main):003:0> h.foo | |
# => "bar" | |
class Hash | |
def method_missing(method, *params) | |
method_string = method.to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The infamous Monkey-Hash. Example: | |
# h = {} | |
# h.foo = "bar" | |
# h.foo # => "bar" | |
class Hash | |
def method_missing(method, *params) | |
key = method.to_s | |
if key =~ /=$/ | |
key = key[0..-2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -W0 | |
# Crush! | |
# Crushes png and jpg images by removing their headers and usually unnessecary data for the web. | |
# Needs pngcrush and jpegtran. | |
# | |
# Usage: | |
# $ crush directory/to/copy new/directory | |
# | |
# Installing pngcrush and jpegtran under OS X: | |
# $ sudo port install pngcrush |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var thoughts = 'Je mange des enfants la nuit. '; | |
window.addEventListener('load', function() { | |
var t = document.getElementById('t'); | |
var text = ''; | |
t.addEventListener('keyup', function () { | |
while (text.length < t.value.length) | |
text += thoughts; | |
t.value = text.slice(0, t.value.length); | |
} , false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' | |
and isset($_GET['user']) and isset($_GET['pass'])) { | |
header('Content-type: text/plain'); | |
echo htmlspecialchars($_GET['user'] . ':' . crypt($_GET['pass'])); | |
exit; | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class String | |
def truncate(length = 30, truncate_string = "...") | |
return self if self.length <= length | |
short_length = length - truncate_string.length | |
self[0...short_length] + truncate_string | |
end | |
end | |
def date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist has moved to : http://github.com/sunny/so-nice | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Small jQuery addons by Sunny Ripert | |
// Returns a boolean to know if jQuery object contains elements | |
// Example: | |
// $('body').exists() # => true | |
// $('#doesnt_exist').exists() # => false | |
$.fn.exists = function() { | |
return $(this).length > 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Calendar class to print out an HTML calendar. | |
* | |
* Usage: | |
* $calendar = new Calendar(); | |
* $calendar->addEvent(2009, 8, 13, '/foo'); | |
* $calendar->addEvent(2009, 8, 28, '/bar', 'After the foo comes the bar'); | |
* $calendar->printMonth(2009, 8); | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✈ |