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 Module | |
original_c_m = instance_method(:const_missing) | |
define_method(:const_missing) do |name| | |
if name.to_s =~ /^U([0-9a-fA-F]{4})$/ | |
[$1.to_i(16)].pack("U*") | |
else | |
original_c_m.bind(self).call(name) | |
end | |
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
require 'digest/sha1' | |
Digest::SHA1.hexdigest(File.read('PATH_TO_FILE')) |
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
irb -r my_sinatra_app.rb |
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
ps -axcr -o "pid,pcpu,pmem,time,comm" |
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
def outer | |
start = 0 | |
anon_fun = lambda { | |
while start < 15 #The lambda has access to the start variable from the outer scope | |
puts "start: #{start}" | |
start += 1 | |
sleep 2 | |
end | |
} | |
anon_fun.call |
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
<html> | |
<head></head> | |
<body> | |
<script type="text/javascript"> | |
//This example shows how to create two functions that share state | |
var MYAPP = {}; //new object | |
MYAPP.Trivia = (function() { | |
var start = 0; | |
return { |
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
//Adds a 'create' function to Object for creating prototypal inheritance | |
if (typeof Object.create !== 'function') { | |
Object.create = function(o) { | |
function F(){} | |
F.prototype = o; | |
return new F(); | |
}; | |
} |
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
var singleton = (function() { | |
var private_variable = 10; | |
function private_func() { | |
return "this is a private function"; | |
} | |
return { | |
public_method_one: function() { | |
//Change the private variable |
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
function base(id) { | |
return { | |
id: id, | |
toString: function() { | |
return "base: "+this.id; | |
} | |
}; | |
} |
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
at_exit { puts "exit 1" } | |
at_exit { puts "exit 2" } | |
#2 runs before 1 -- reverse order of execution |