This file contains 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
#http://tools.ietf.org/html/rfc2397 | |
img_path = '...pictures/img.jpg' | |
img = File.open(img_path, 'rb').read | |
img_type = case img[0..10] | |
when /^GIF8/ | |
'gif' | |
when Regexp.new('^\x89PNG', nil, 'n') | |
'png' | |
when Regexp.new('^\xff\xd8\xff\xe0\x00\x10JFIF', nil, 'n'), Regexp.new('^\xff\xd8\xff\xe1(.*){2}Exif', nil, 'n') | |
'jpeg' |
This file contains 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
require 'date' | |
# Converts a german date string to a Time object | |
# The format of the german date is '%A, %d. %B %Y, %H:%M Uhr' | |
# e.g.: 'Dienstag, 29. Januar 2013, 19:27 Uhr' | |
# | |
# @params [String] german date | |
# @return [Time] | |
def intl_time(de_date) | |
en_days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] |
This file contains 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
class Integer | |
def digit_sum(base = 10) | |
result = 0 | |
number = self | |
while(number > 0) do | |
result += number % base | |
number /= base | |
end | |
result | |
end |
This file contains 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
/*Run this code in your js console after the page has been loaded completely*/ | |
/* "!== undefined" at the end simply prevents unwanted output in the js console.*/ | |
$('a').each(function () { | |
var self = $(this); | |
if ((self.attr('href') && self.attr('href').indexOf('#') !== 0) && (self.data('events') !== undefined) && (self.data('events').click !== undefined)) { | |
console.log(this, self.attr('href'), self.data('events')) | |
} | |
}) !== undefined | |
$('[type="submit"]').each(function () { |
This file contains 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
MyApp::Application.configure do | |
#... | |
# Print deprecation notices to the stderr | |
#config.active_support.deprecation = :stderr | |
# Print full stacktrace from deprecation warnings | |
config.active_support.deprecation = Proc.new { |message, callstack| | |
$stderr.puts message, callstack |
This file contains 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
require 'openssl' | |
class String | |
def encrypt(key) | |
cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt | |
cipher.key = Digest::SHA1.hexdigest key | |
s = cipher.update(self) + cipher.final | |
s.unpack('H*')[0].upcase | |
end |
This file contains 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
# HINT: This gists uses GNU commands. On Mac OS, you might want to adopt the script or use `grep`, `find` and `sed` "--with-default-names". | |
RENAME_FROM=old_name | |
RENAME_TO=new_name | |
# RENAME files, directories from an old name to a new name | |
# CHECK files manually: find . -type f -name "*$RENAME_FROM*" | grep -v '/\.' | |
# find . -type f -name "*$RENAME_FROM*" ## find all files that contain the old name | |
# grep -v '/\.' ## exclude hidden files |
This file contains 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
# grep -l -R -I --exclude "*.log" -e "old_stuff" . ## list files that contain old_stuff, excluding .log files | |
# grep -v '/\.' ## don't list dot files | |
# xargs sed -i "s/old_stuff/new_stuff/g" ## replace (and save) old_stuff with new_stuff in those files. | |
grep -l -R -I --exclude "*.log" -e "old_stuff" . | grep -v '/\.' | xargs sed -i "s/old_stuff/new_stuff/g" |
This file contains 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
/* | |
because IE8 doesn't support Object.keys... | |
*/ | |
Object.keys = Object.keys || function(o) { | |
var result = []; | |
for(var name in o) { | |
if (Object.prototype.hasOwnProperty.call(o,name)) { | |
result.push(name); | |
} | |
} |
This file contains 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
/* go to https://elgoog.im/breakout/ and run the snippet in your js console (works only for one level): */ | |
hit = function($) { $('#breakout-paddle').style.left = (parseInt($('#breakout-ball').style.left, 10)-50).toString()+'px'; window.setTimeout(function(){ hit($); }, 10)}; hit($); |
OlderNewer