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
h = {:'->' => ->(x) {x}} | |
h[:'->']['->'] # => "->" |
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 A | |
def self.inherited inheriter | |
class << inheriter | |
def inherited inheriter | |
Object.const_set inheriter.name.to_sym, self | |
p "Sorry, A can't have grandchildren. You, #{inheriter}, are instead to be of class #{self}." | |
end | |
end | |
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
; lisp | |
(defmacro x-injector () | |
'x) |
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
->(_){[200,{},'']} | |
# I have no idea why I wanted to write this down, honestly. |
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
// I don’t care if | |
IOPIN0 & (1<<23); | |
// means anything to you. it doesn’t mean anything to me. | |
// So let’s move it to a method, which, when called, will | |
// make everything clear for everybody. | |
int isUSBConnected(void) { | |
return IOPIN0 & (1<<23); |
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
// Say, you want only to use the latest arriving ajax request. | |
// For example in a search engine, where only the request of the | |
// most recently sent request is of interest. Responses that come | |
// after and have been sent before the one that has already arrived | |
// are ignored: | |
// remember the latest request date | |
// | |
var latestRequestDate = new Date(); | |
function responseHandler() { |
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
# In your unicorn.rb | |
# | |
after_fork do |server, worker| | |
GC.disable | |
end | |
# The rack app. | |
# | |
Responder = lambda do |env| | |
harakiri |
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 Array | |
# Note: Could also be called ary_join. | |
# | |
def real_join element | |
combined = [element]*(size-1) | |
zip(combined).flatten.compact | |
end | |
end | |
p [1,2,3,4].real_join 'and' #=> [1, 'and', 2, 'and', 3, 'and', 4] |
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
# Just copy in TextMate and play | |
# | |
class Chain | |
def initialize lambdas | |
@lambdas = lambdas | |
end | |
# Wrapper. | |
# | |
def self.[] lam, *args |
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
matrix = lambda { |x| lambda { |y| x*y**2 }} | |
p matrix[-3][-10] #=> -300 | |
p matrix[0][0] #=> 0 | |
p matrix[3][4] #=> 48 | |
p matrix[10][20] #=> 4000 |