Skip to content

Instantly share code, notes, and snippets.

Josh Clayton joshuaclayton

Block or report user

Report or block joshuaclayton

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
joshuaclayton / hash_flattener.rb
Created Jul 5, 2018
Flatten deeply-nested hashes
View hash_flattener.rb
def recursive_flatten(input, keys = [], acc = {})
input.keys.each do |k|
result_key = keys + [k]
if input[k].is_a?(Hash)
recursive_flatten(input[k], keys + [k], acc)
elsif input[k].is_a?(Array) && input[k].any? {|v| v.is_a?(Hash) }
input[k].each_with_index do |array_value, index|
result_key_with_index = keys + [k, "[#{index}]"]
View foo.hs
module Time.DateConversions
-- current day from system
, today
-- average
, averageDaysBetween
-- beginning of period

This is a rough draft (which works!) handling file composition for vim-projectionist.

Each of the *.json files live in ~/.projections, and projections lives somewhere in your $PATH. This uses jq to combine multiple JSON files into one. With navigation.zsh, we hook into cding into a directory, run projections, and if there's a 0 exit code, overwrite the output to .projections.json, which vim-projectionist then uses.

I've updated my ~/.gitignore to ignore .projections.json, so I'm not concerned about things messing up git.

View -
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z_.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z_.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z_.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z_.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z_.]+)[ \t]+=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@([A-Za-z_.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z_.]+):[^->\n]*$/\1/f,field/
View BenchGroupBy.hs
-- ghc -O --make BenchGroupBy.hs && ./BenchGroupBy --output bench_group.html&& open bench_group.html
import Criterion.Main
import Control.Arrow ((&&&))
import qualified Data.List as L
import Data.Function
main = defaultMain [
bgroup "group" [ bench "old" $ nf oldGroupBy numbers
, bench "new" $ nf newGroupBy numbers
View BenchStringToInt.hs
-- ghc -O --make BenchStringToInt.hs && ./BenchStringToInt --output bench_string_to_int.html&& open bench_string_to_int.html
import Criterion.Main
import Data.Maybe (fromMaybe)
import Text.Parsec (parse)
import Text.Parsec.Token (makeTokenParser, integer)
import Text.Parsec.Language (haskellStyle)
import Data.Char (digitToInt, isDigit)
main = defaultMain [
joshuaclayton / 0_reuse_code.js
Created Sep 22, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
joshuaclayton /
Last active Jun 1, 2018
RSpec custom matchers for tracking
View lists-broken.scss
$tablet: new-breakpoint(max-width 768px 8);
$mobile: new-breakpoint(max-width 480px 8);
li.location {
@include span-columns(4);
@include omega(3n);
@include media($tablet) {
@include span-columns(4);
@include omega(2n);
View 3.2 test output
[ ~/dev/gems/factory_girl master ] ✔ rake appraisal:3.2 spec:acceptance ☺ 1.9.3-p429
>> BUNDLE_GEMFILE=/Users/joshuaclayton/dev/gems/factory_girl/gemfiles/3.2.gemfile bundle exec /Users/joshuaclayton/.rbenv/versions/1.9.3-p429/bin/rake spec:acceptance
/Users/joshuaclayton/.rbenv/versions/1.9.3-p429/bin/ruby -S rspec spec/acceptance/activesupport_instrumentation_spec.rb spec/acceptance/aliases_spec.rb spec/acceptance/attribute_aliases_spec.rb spec/acceptance/attribute_existing_on_object_spec.rb spec/acceptance/attributes_for_spec.rb spec/acceptance/attributes_from_instance_spec.rb spec/acceptance/attributes_ordered_spec.rb spec/acceptance/build_list_spec.rb spec/acceptance/build_spec.rb spec/acceptance/build_stubbed_spec.rb spec/acceptance/callbacks_spec.rb spec/acceptance/create_list_spec.rb spec/acceptance/create_spec.rb spec/acceptance/define_child_before_parent_spec.rb spec/acceptance/defining_methods_inside_a_factory_spec.rb spec/acceptance/definitio
You can’t perform that action at this time.