Skip to content

Instantly share code, notes, and snippets.

View rorhug's full-sized avatar
📀
out on dvd

Rory Hughes rorhug

📀
out on dvd
View GitHub Profile
@rorhug
rorhug / tco.rb
Created April 6, 2014 17:31
Ruby tail recursion
RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
@rorhug
rorhug / search.sql
Created April 1, 2014 16:51
Postgres full text search example
# Note Load (30.9ms)
SELECT "notes".*, (
(ts_rank(
(
to_tsvector('english', unaccent(
coalesce("notes"."title"::text, '')
)) || to_tsvector('english', unaccent(
coalesce("notes"."short_text"::text, '')
))
@rorhug
rorhug / gist:9177147
Created February 23, 2014 20:55
dokku troublshoot
~/dokku
total 56
-rw-r--r-- 1 root root 732 Feb 23 18:36 AUTHORS
-rw-r--r-- 1 root root 738 Feb 23 18:36 bootstrap.sh
drwxr-xr-x 2 root root 4096 Feb 23 18:36 contrib
drwxr-xr-x 2 root root 4096 Feb 23 18:36 docs
-rwxr-xr-x 1 root root 3032 Feb 23 18:36 dokku
-rw-r--r-- 1 root root 845 Feb 23 18:36 HISTORY.md
-rw-r--r-- 1 root root 1055 Feb 23 18:36 LICENSE
-rw-r--r-- 1 root root 2072 Feb 23 18:36 Makefile
@rorhug
rorhug / s2.py
Created February 22, 2014 18:56
final 2014 q2
room_count = int(raw_input())
def tb(x):
return x == "*"
def get_room_in_bools():
height, width = [ int(y) for y in raw_input().split(" ") ]
return [ [ tb(x) for x in list(raw_input()) ] for y_axis in xrange(0, height) ]
room_grids = [get_room_in_bools() for x in xrange(0, room_count)]
@rorhug
rorhug / q3.py
Created February 21, 2014 23:27
aipo final 2013 q3
n = int(raw_input())
a = [ int(raw_input()) for x in range(n) ]
average_count = 0
for (i, el) in enumerate(a):
a.pop(i) # remove that element
for to_avg_with in a:
avg = (el + to_avg_with) / 2
if avg in a:
average_count += 1
@rorhug
rorhug / q2.py
Created February 21, 2014 21:01
aipo 2013 q2
import math
def is_whole(x):
return x % 1 == 0
n = int(raw_input())
c_list = set()
c = 5
while len(c_list) < n:
@rorhug
rorhug / gulpfile.js
Created February 19, 2014 15:01
XtraGulpFile
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
// var uglify = require('gulp-uglify');
var nodemon = require('gulp-nodemon');
var sass = require('gulp-sass');
var StreamQueue = require('streamqueue');
@rorhug
rorhug / gist:9080955
Created February 18, 2014 21:48
Database dilema
DB ORM Lang
MongoDB(ok but no joins) + Mongoose(Great) + Node.js(Great)
Postgres(ok but schemas) + Sequelize(Great) + Node.js(Great)
RethinkDB(Great) + Thinky(ok but no validations) + Node.js(Great)
RethinkDB(Great) + nobrainer(Great) + Ruby(Good but already started app in Node.js and a little slow)
@rorhug
rorhug / gulpfile.js
Created February 9, 2014 17:12
merging streams
// Sass and css libs
gulp.task('css', function () {
var sassStream = gulp.src('./assets/*.scss').pipe(sass());
var cssFiles = gulp.src('./assets/csslib/*.css');
var queue = new StreamQueue();
queue.queue(
cssFiles,
sassStream
);
@rorhug
rorhug / countdown.js
Created December 13, 2013 18:26
Countdown with padded seconds
// set the date we're counting down to
var target_date = new Date("Aug 15, 2019").getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
// update the tag with id "countdown" every 1 second