Skip to content

Instantly share code, notes, and snippets.

@c0
c0 / _generate-merkle-tree.js
Last active February 3, 2022 00:05
Merkle Trees for Whitelisting
// Take a list of addresses from path-to-addresses.txt, create a merkle tree, and store it in example-tree.json
const fs = require('fs')
const { MerkleTree } = require('merkletreejs')
const keccak256 = require('keccak256')
const { createMerkleTree } = require('../utils/merkle')
const addresses = fs.readFileSync('path-to-addresses.txt').toString().split('\n')
const { leaves, tree, root } = createMerkleTree(addresses)
@c0
c0 / stimulus.js
Last active January 26, 2022 16:07
import { mind, body } from './me'
const OVER_STIMULUS_THRESHOLD = 0.33
const UNDER_STIMULUS_THRESHOLD = 0.01
mind.on('stimulus', () => {
if (mind.stimulusRate > OVER_STIMULUS_THRESHOLD) {
['walk','exercise','medidate','write'].rand().go()
}
if (mind.stimulusRate < UNDER_STIMULUS_THRESHOLD) {
@c0
c0 / enable.vcl
Last active February 10, 2017 10:11
gzip vcl recommendations from fastly
if ( req.http.accept-encoding == "gzip" && beresp.http.content-type ~ "^(text/html|application/x-javascript|text/css|application/javascript|text/javascript)" ) {
# Header rewrite Force GZIP : 10
set beresp.gzip = true;
}
if ( beresp.http.content-type ~ "^(text/html|application/x-javascript|text/css|application/javascript|text/javascript)" ) {
# Header rewrite Vary Encoding : 10
set beresp.http.Vary = beresp.http.Vary ",Accept-Encoding";
}
alias fp='g fetch -p && pull'
alias dev='git checkout dev; fp'
alias amend='git commit --amend --no-edit'
alias add='git add --patch'
alias intent='git add --intent-to-add .; add'
alias force-push='git push -f origin `branch-name`'
class Bottles
attr_accessor :bottle_number_factory
def initialize(bottle_number_factory = BottleNumberFactory)
@bottle_number_factory = bottle_number_factory
end
def song
verses(99, 0)
end
gem 'minitest', '~> 5.3'
require 'minitest/autorun'
require_relative '../lib/six_packs'
class SixPacksTest < Minitest::Test
attr_reader :six_packs
def setup
@six_packs = ::SixPacks.new
end
class Bottles
def song
starting_bottle_number = 99
ending_bottle_number = 0
verses(starting_bottle_number, ending_bottle_number)
end
def verses(starting_bottle_number, ending_bottle_number)
starting_bottle_number.downto(ending_bottle_number).map do |bottle_number|
verse(bottle_number)
@c0
c0 / six_packs.rb
Created May 21, 2014 20:40
Six Packs Open / Closed 2
require_relative 'bottles'
class SixPacks < Bottles
def container_name(quantity)
if quantity % 6 == 0 && quantity > 0
quantity > 6 ? 'six packs' : 'six pack'
else
super
end
end
@c0
c0 / six_packs.rb
Last active August 29, 2015 14:01
Six Packs gsub
require_relative 'bottles'
class SixPacks < Bottles
def verse(quantity)
if quantity % 6 == 0 && quantity == 6
super.gsub("#{quantity} bottles", "#{(quantity / 6)} six pack")
elsif quantity % 6 == 0
super.gsub("#{quantity} bottles", "#{(quantity / 6)} six packs")
else
super