Skip to content

Instantly share code, notes, and snippets.

View j16r's full-sized avatar
😑

John Barker j16r

😑
  • Colorado
View GitHub Profile
package sets
import "testing"
func BenchmarkUnitSet(b *testing.B) {
for i := 0; i < b.N; i++ {
values := make(map[int]struct{})
for j := 0; j < 1000; j++ {
values[j] = struct{}{}
}
@j16r
j16r / gist:ac274feb99780bac85f5
Created June 25, 2015 15:05
Golang and ParseECPrivateKey
# According to the go src (https://github.com/golang/go/blob/master/src/crypto/x509/sec1_test.go)
# this is how to use openssl to generate an EC private key. Go can't read it
# however.
# openssl ecparam -name secp521r1 -genkey -param_enc explicit -outform PEM -out $@
# e.g:
got asn1: structure error: tags don't match (6 vs {class:0 tag:16 length:450 isCompound:true}) {optional:false ex
plicit:false application:false defaultValue:<nil> tag:<nil> stringType:0 set:false omitEmpty:false} ObjectIdentifier @4
# For debugging the private key
@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],
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: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)
@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 / 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 / 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 / gist:4122564
Created November 21, 2012 01:52
Judgement Day
Time.utc(1997, 8, 4, 7, 14)
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