Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
AJFaraday / gist:9951279
Created April 3, 2014 09:25
debugging methodology
if x
...
elsif y
...
else
puts "You screwed up."
end
@AJFaraday
AJFaraday / gist:2ee07be60ac7af5f7a6c
Created May 11, 2014 16:42
Failed make install for pure data on SUSE
pdlua.c:244:16: warning: unused parameter ‘L’ [-Wunused-parameter]
lua_State *L, /**< Lua interpreter state. */
^
pdlua.c: In function ‘pdlua_popatomtable’:
pdlua.c:1059:9: warning: implicit declaration of function ‘lua_objlen’ [-Wimplicit-function-declaration]
*count = lua_objlen(L, -1);
^
pdlua.c: In function ‘pdlua_dofile’:
pdlua.c:1558:17: error: too few arguments to function ‘lua_load’
if (lua_load(L, pdlua_reader, &reader, filename))
@AJFaraday
AJFaraday / gist:c9adb7db47eca8230246
Created May 11, 2014 22:47
failed make install for pure data post 5.2 changes...
make -C /home/biorails/Downloads/pd-extended/externals/loaders/pdlua/src PD_PATH=/home/biorails/Downloads/pd-extended/pd CFLAGS="-DPD -DHAVE_G_CANVAS_H -DZEXY_LIBRARY -I/home/biorails/Downloads/pd-extended/pd/src -Wall -W -ggdb -I/home/biorails/Downloads/pd-extended/externals/Gem -I/home/biorails/Downloads/pd-extended/externals/pdp/include -DUNIX -Dunix -DDL_OPEN -fPIC"
make[3]: Entering directory `/home/biorails/Downloads/pd-extended/externals/loaders/pdlua/src'
compiling pdlua version 0.6
cflags are -DPD -DHAVE_G_CANVAS_H -DZEXY_LIBRARY -I/home/biorails/Downloads/pd-extended/pd/src -Wall -W -ggdb -I/home/biorails/Downloads/pd-extended/externals/Gem -I/home/biorails/Downloads/pd-extended/externals/pdp/include -DUNIX -Dunix -DDL_OPEN -fPIC
optcflags are -O3 -funroll-loops -march=k8 -msse -msse2 -msse3 -mfpmath=sse -ftree-vectorize -ftree-vectorizer-verbose=1
luacflags are -DVERSION='0.6' -I/usr/include/lua
ldflags are -Wl,--export-dynamic -shared -fPIC
libs are -llua -lc
cc -DPD -DHAVE_G_CANVAS_H -DZEXY_
@AJFaraday
AJFaraday / gist:97b9288919ab7f6dfd15
Created May 13, 2014 21:51
Generate green-red fade classes in ruby for SCSS
i = 0
r = 0.0
g = 255.0
101.times do
puts <<-TEXT
.heat-map-#{i} {
@AJFaraday
AJFaraday / gist:18fc83b96b153ce2b3e9
Last active August 29, 2015 14:01
Pure Data audio issues
ajfaraday@scaled-up:/opt/scaled_up$ pd-extended -open pd/test-tones.pd -alsa -listdev -nogui
audio input devices:
1. HDA NVidia (hardware)
2. HDA NVidia (plug-in)
audio output devices:
1. HDA NVidia (hardware)
2. HDA NVidia (plug-in)
API number 1
no midi input devices found
order_table = Order.arel_table
arel = Order.where(order_table[:id].not_in([]))
sql = arel.to_sql
puts sql
#=> SELECT "ORDERS".* FROM "ORDERS" WHERE ("ORDERS"."ID" NOT IN (NULL))
@AJFaraday
AJFaraday / gist:8003815a243575eb06ac
Created July 16, 2014 09:56
Possible ruby bug (1.9.3) else without an if is ignored...
def test_method
@var = 'a'
else
@var = 'b'
end
test_method
@var #=> 'b'
irb(main):024:0> Benchmark.measure{1_000_000.times{'hello'}}
=> 0.210000 0.000000 0.210000 ( 0.202565)
irb(main):025:0> Benchmark.measure{1_000_000.times{:hello}}
=> 0.050000 0.000000 0.050000 ( 0.046498)
irb(main):026:0> Benchmark.measure{10_000_000.times{'hello'}}
=> 1.500000 0.000000 1.500000 ( 1.499443)
irb(main):027:0> Benchmark.measure{10_000_000.times{:hello}}
@AJFaraday
AJFaraday / gist:676c6c59c7c922f9d148
Created July 31, 2014 09:22
Why use symbols instead of strings:
irb(main):024:0> Benchmark.measure{1_000_000.times{'hello'}}
=> 0.210000 0.000000 0.210000 ( 0.202565)
irb(main):025:0> Benchmark.measure{1_000_000.times{:hello}}
=> 0.050000 0.000000 0.050000 ( 0.046498)
irb(main):026:0> Benchmark.measure{10_000_000.times{'hello'}}
=> 1.500000 0.000000 1.500000 ( 1.499443)
irb(main):027:0> Benchmark.measure{10_000_000.times{:hello}}
# gsub! doesn't return anything when no changes are made
irb(main):006:0> 'abc'.gsub('c','d')
=> "abd"
irb(main):007:0> 'abc'.gsub!('c','d')
=> "abd"
irb(main):008:0> 'abc'.gsub!('d','c')
=> nil
# It's usual usage pattern (working on an existing object) still works