Skip to content

Instantly share code, notes, and snippets.

Avatar

TJ Singleton tjsingleton

View GitHub Profile
View lazy.js
function lazyCompileFactory(id, html) {
crunch.global.templates[id] = function(context) {
var compiled = Handlebars.compile(html);
crunch.global.templates[id] = compiled;
return compiled(context);
}
}
$('script[type="text/x-handlebars-template"]').each(function() {
var text = this.textContent;
@tjsingleton
tjsingleton / watch.rb
Last active Dec 16, 2015
watch a dir for new files and do some work
View watch.rb
require 'listen'
require 'rb-fsevent'
LISTEN_PATH = '/tmp/m'
consumer, producer = IO.pipe
Dir["#{LISTEN_PATH}/*"].each {|n| producer.puts n }
2.times do
View destructure.rb
require 'benchmark/ips'
Benchmark.ips do |x|
RESULT = [1]
x.report('first') do |times|
i = 0
while i < times
id = RESULT.first
i += 1
View script_bench.rb
require 'benchmark/ips'
require_relative '../config/environment'
Benchmark.ips do |x|
x.report("without patch - by slug") {
User.uncached do
User.find("tj-singleton")
end
}
View replace.sql
CREATE TABLE report (
account_id INT UNIQUE,
classification VARCHAR(11)
);
CREATE TABLE report_temp (
account_id INT UNIQUE,
classification VARCHAR(11)
);
View preload_association.rb
cl = ContentLicense.last
cl.content.object_id == cl.presentation.content.object_id
#=> false
cl.reload
cl.association(:content).target = cl.presentation.content
>> cl.content.object_id == cl.presentation.content.object_id
#=> true
View names.js
names = [
"ERock560",
"jeep19950",
"meltin-BARRELS",
"RMAN2010",
"maden471",
"zeSPACE_NAZl",
"mud-racer2005",
"RICHIEJMONEY",
"yotamallcrawler",
@tjsingleton
tjsingleton / dig_cube.lua
Created Aug 4, 2012
makes the turtle dig a cube
View dig_cube.lua
turn_right = true
function dig_forward()
turtle.dig()
turtle.forward()
end
function dig_down()
turtle.digDown()
turtle.down()
View resize_images.rb
require 'pathname'
ROOT = Pathname.pwd
SIZES = %W[
1056x792
1162x871
1278x958
1406x1054
1546x1160
1701x1276
@tjsingleton
tjsingleton / test.c
Created Jun 19, 2012
test type conversion
View test.c
#include <stdio.h>
int main() {
unsigned long dword;
char converted;
dword = 255L;
converted = (char) dword;
printf("value is: %lu\n", dword);
printf("value is: %lu\n", converted);