Skip to content

Instantly share code, notes, and snippets.

@txus
txus / Rakefile
Last active December 21, 2015 03:19
Tasks depend on other tasks
task :ring_alarm do
puts "RIIIIIIING"
end
task :wake_up => :ring_alarm do
puts "Whwhoooooaaa what a nice day! Just woke up!"
end
task :dress_up => :wake_up do
puts "Yeah, I'm dressing up"
@txus
txus / lani.rex
Created August 15, 2013 14:16
Lexer structure
class Lani::Parser
macro
# our macros go here
rule
# our rules go here
inner
# here we put any ruby code we want to extend our lexer with.
# for example, our own tokenize method.
def tokenize(code)
scan_setup(code)
@txus
txus / let.rb
Created August 9, 2013 14:10
Default arguments in argument lists to have kind of let*s
foo = lambda do |a, b=a.upcase|
b
end
p foo["hey"] # => "HEY"
@txus
txus / function_composition.coffee
Last active December 20, 2015 05:19
Function Composition in Javascript
comp = (fns...) ->
(arg) ->
fns.reverse().reduce((x, fn) ->
fn(x)
, arg)
timesthree = (a) -> a * 3
timestwo = (a) -> a * 2
negative = (a) -> -a
@txus
txus / afk.rb
Created July 15, 2013 14:45
AFK
while true
value = rand > 0.8 ? "\e[031mF\e[0m" : "\e[032m.\e[0m"
print value
sleep rand / 2
end
@txus
txus / .pryrc.rb
Last active December 18, 2015 17:59
Pry command to trace a method invocation and log backtraces of each invocation to a file.
def write_backtrace name, backtrace, filename
exceptions = Regexp.union([
/\.bundle/,
/spec/,
/test/,
/lib\/ruby\/1.9.1/
])
backtrace.reject! { |line| line =~ exceptions }
@txus
txus / sinatra.rb
Created June 5, 2013 09:50
Disabled and checked checkboxes aren't sent in post requests.
# app.rb
#
# Usage:
#
# $ gem install sinatra
# $ ruby app.rb
#
require 'sinatra'
get '/' do
@txus
txus / foo.hs
Last active December 18, 2015 00:29
Get complex methods from Cane output
import Data.List (intersperse)
tuplify3 :: [a] -> (a,a,a)
tuplify3 [x,y,z] = (x,y,z)
violations :: String -> [(String, String, String)]
violations = (map tuplify3) . (map words) . lines
methodName :: (String, String, String) -> String
methodName (_, x, _) = x
curried_add = -> a, b, c { a + b + c }.curry
add3 = curried_add[3]
add3and4 = add3[4]
add3and4[10] # => 17
@txus
txus / crash
Created May 27, 2013 10:03
Crash
Rubinius Crash Report #rbxcrashreport
Error: signal SIGSEGV
[[Backtrace]]
0 ruby 0x0000000105c82650 _ZN8rubiniusL12segv_handlerEi + 544
1 libsystem_c.dylib 0x00007fff8b72994a _sigtramp + 26
2 ??? 0x00007f9ae211db70 0x0 + 140303194512240
3 profiler_vm.bundle 0x000000010a750c71 _ZN8profiler12_GLOBAL__N_117tool_enter_methodEPN5rbxti3EnvEPNS1_14InternalObjectEPNS1_14InternalSymbolEPNS1_14InternalModuleEPNS1_20InternalCompiledCodeE + 257
4 ruby 0x0000000105cf4370 _ZN8rubinius11MachineCode19execute_specializedINS_11OneArgumentEEEPNS_6ObjectEPNS_5StateEPNS_9CallFrameEPNS_10ExecutableEPNS_6ModuleERNS_9ArgumentsE + 1024