Skip to content

Instantly share code, notes, and snippets.

Cameron Martin cameron-martin

Block or report user

Report or block cameron-martin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
cameron-martin /
Created Jul 24, 2019
Javascript CSS Preprocessor


Existing CSS preprocessors kinda suck:

  • Values cannot be easily shared between javascript and CSS, sometimes resulting in duplication
  • They're not suited to doing complicated computation. Want to do trigonometry in SASS? Not super easy. Moreover, writing
  • Modules don't exist for library code.


cameron-martin / router-idea.ts
Last active Jul 24, 2019
A typesafe router sketch
View router-idea.ts
interface RouteVariable<T> {
parse(value: string): { value: T, rest: string } | false;
const int: RouteVariable<number> = undefined as any;
const segment: RouteVariable<string> = undefined as any;
type RouteVariables<T> = { [K in keyof T]: RouteVariable<T[K]> };
type AddRoute<R> = <T extends any[]>(
View promise_pipelining.js
var pipeline = [
function(title) {
return Promise.resolve(title.replace(/P/g, 'p'));
function(title) {
return Promise.resolve(title.replace(/p/g, 't'));
function combinePipeline(pipeline) {
View gist:b907ec43a9d8b9303bdc
require 'benchmark'
require 'ostruct'
n = 10_000
array = { |index| { |struct| struct.price = index } };
Benchmark.bmbm do |x|'two stages') { n.times {, :+) } }'one stage') { n.times { array.inject(0) { |sum, product| sum += product.price } } }
cameron-martin / gist:08abeaeae1bf746ef718
Last active Aug 29, 2015
Asynchronous vs synchronous
View gist:08abeaeae1bf746ef718
require 'eventmachine'
require 'benchmark'
rand_iterations = 10
define_method(:generate_func) do
# This is so we have n different function objects, which seems more realistic
proc { rand_iterations.times { rand(0..10) } }
View hstore_accessor.rb
# include from an initializer
module HstoreAccessor
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
define_method("#{key}=") do |value|
send("#{hstore_attribute}=", (send(hstore_attribute) || {}).merge(key.to_s => value))
define_method(key) do
View gist:a7a91f0bc952e8a5c795
require 'benchmark'
n = 1_000_000
(1..50).step(5) do |length|
puts "Length: #{length}" do |x|'array') { n.times { { rand(36).to_s(36) }.join } }
You can’t perform that action at this time.