Skip to content

Instantly share code, notes, and snippets.

View j16r's full-sized avatar
😑

John Barker j16r

😑
  • Colorado
View GitHub Profile
@j16r
j16r / sample.rb
Created December 18, 2010 07:59
Quick script to shuffle a directory full of files into a test and training set
require 'fileutils'
# Given a directory of files, sort them randomly then split into a training and
# test set
TEST_PERCENT = 20
if ARGV.size < 1
puts "Usage: #{$0} <path> (outdir)"
exit 0
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 14952 | 11972 | 128 | 834 | 6 | 12 |
| Helpers | 1984 | 1453 | 2 | 212 | 106 | 4 |
| Models | 19054 | 13238 | 186 | 1722 | 9 | 5 |
| Libraries | 4798 | 3385 | 27 | 357 | 13 | 7 |
| Model specs | 21536 | 17069 | 6 | 27 | 4 | 630 |
| View specs | 200 | 154 | 0 | 0 | 0 | 0 |
| Controller specs | 14980 | 11166 | 1 | 34 | 34 | 326 |
def diff(a, b, file = "current.diff")
require 'rspec/expectations/differ'
differ = RSpec::Expectations::Differ.new
diff = differ.diff_as_object(a, b)
File.open(file, "w+") { |f| f.write diff }
system "mate", file
end
@j16r
j16r / gist:4122564
Created November 21, 2012 01:52
Judgement Day
Time.utc(1997, 8, 4, 7, 14)
@j16r
j16r / learn you a haskell for great good
Created December 19, 2012 02:18
Experimenting with Haskell while reading Learn you a Haskell for Great Good
{-# LANGUAGE ExistentialQuantification #-}
module Main where
import qualified Data.List as L
import qualified Data.Map as Map
{- How to make a heteregenous list of showable items, taken from
- http://www.haskell.org/haskellwiki/Heterogenous_collections-}
data Showable = forall a . Show a => MkShowable a
@j16r
j16r / Timeout rspecs
Created February 22, 2013 14:33
Useful for adding a strict timeout to functionality you need to operate within a certain time frame
config.around(:each) do |example|
if timeout = example.metadata[:timeout]
Benchmark.realtime do
example.call
end.should <= timeout
else
example.call
end
end
@j16r
j16r / tree.rs
Last active December 29, 2015 20:49
An attempt to make a simple tree implementation in rust
use std::util::swap;
#[deriving(Eq)]
pub enum Tree {
Text(~str),
Cons(~Tree, ~Tree),
Nil
}
pub fn first<'r>(tree: &'r Tree) -> &'r Tree {
@j16r
j16r / gist:8736407
Created January 31, 2014 17:07
Do you need $apply when using $q.resolve outside of Angular's event loop?
setTimeout(function(){
$scope.$apply(function(){
deferred.resolve(message);
});
}, 5)
struct Queue<T, size> {
items : [T]
}
impl<T, size> Queue<T, size> {
pub fn new() -> Queue<T, size> {
Queue { items : [T, ..size] }
}
}
@j16r
j16r / gist:4969f4bfd961944db685
Created June 27, 2014 01:02
Generic Queue with Iterator
use std::default::Default;
struct Q<T> {
items : [T, ..10],
count : uint
}
impl<T : Default + Copy> Q<T> {
pub fn new() -> Box<Q<T>> {
box Q {items: [Default::default(), ..10],