Skip to content

Instantly share code, notes, and snippets.

View sunny's full-sized avatar
☀️

Sunny Ripert sunny

☀️
View GitHub Profile
# 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
# 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]
#!/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
<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);
<?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">
@sunny
sunny / gist:25917
Created November 17, 2008 21:38 — forked from sr/gist:25914
#!/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
@sunny
sunny / README
Created November 26, 2008 14:55
Itunes-Sinatra web app
This gist has moved to : http://github.com/sunny/so-nice
// 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;
}
<?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);
*/
@sunny
sunny / gist:53587
Created January 27, 2009 21:52 — forked from sr/gist:53511