Skip to content

Instantly share code, notes, and snippets.

View jah2488's full-sized avatar

Justin Herrick jah2488

View GitHub Profile
@jah2488
jah2488 / Main.elm
Last active March 21, 2017 16:38
Do now for Tuesday the 21st of March. Converting a string into a dictionary by last names.
module Main exposing (..)
import Html exposing (Html, div, text)
import Dict exposing (Dict)
names : String -> Dict String (List String)
names str =
str
|> String.split ", "
|> List.map (\name -> String.split " " name)
# Structured and Nested
obj = {
container_a = {
name: "Foo",
contents: [item_a, item_b, item_e]
}
container_b = {
name: "Bar",
contents: [item_c, item_d, item_z]
}
it 'sets the state to "gameover" when there is a winner' do
game = Game.new
game.state = "running"
expect { game.winner! }.to change { game.state }.from("running").to("gameover")
end
@jah2488
jah2488 / Main.elm
Created August 8, 2016 21:35
New User form in Elm
module Main exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.App as App
import Html.Events exposing (onInput, onBlur, onClick)
import String exposing (length, left, dropLeft, slice, filter, fromList, toList)
import Char exposing (isDigit)
import Json.Decode as JsonD
import Json.Encode as JsonE
@jah2488
jah2488 / kata.rb
Created July 12, 2016 14:45
A ruby script for generating an empty kata project.
#!/usr/bin/env ruby
# This script will create the folder structure and files
# needed for doing a kata using TDD.
kata_name = (ARGV[0] || 'morning')
dir_name = kata_name + "_kata"
# These are all the commands we will run
# in the order in which we will run them.
@jah2488
jah2488 / commands.sh
Last active July 6, 2016 16:12
Run the following set of commands from folder your download the seed file into to test locally.
rm my_blog.db ; ruby seed.rb | sqlite3 my_blog.db && sqlite3 my_blog.db
def inspect_class(klass)
klass.new.methods.sort.each do |meth|
just = klass.new.methods.sort.max_by(&:length).length
hjust = just / 2
klass_meth = klass.new.method(meth)
label = "#{klass}.new.#{meth.to_s.ljust(just)}"
location = "is defined in #{klass_meth.owner.to_s.ljust(hjust)}"
response = [label, location]
@jah2488
jah2488 / fancy_logger_dsl.rb
Last active June 1, 2016 14:34
First attempt at a light weight logging DSL that makes logging/debugging complicated processes easier to read.
require 'pry'
module Logger
def log(title, opts = {})
__blocks[title] = {
successful: true,
parent: __blocks[:current],
cascade: opts.fetch(:cascade, false)
}
__blocks[:current] = title
@jah2488
jah2488 / memoize_and_reset.rb
Created April 24, 2016 23:50
I feel like there is a whole blog post in here.
class Test
def initialize
puts "I've been created"
end
end
module Foo
def self.check
tester
@jah2488
jah2488 / git-open.rb
Last active February 3, 2016 21:39
A custom git "plugin" that allows you to open git repos on Github.com by saying "git open" from inside the repo. This file needs to be chmod +x and needs to be in your path and needs the extension removed.
#!/usr/bin/env bash
# vim: set ft=ruby:
# This file executes as a bash script, which turns around and executes Ruby via
# the line below. The -x argument to Ruby makes it discard everything before
# the second "!ruby" shebang. This allows us to work on Linux, where the
# shebang can only have one argument so we can't directly say
# "#!/usr/bin/env ruby --disable-gems". Thanks for that, Linux.
#
# If this seems confusing, don't worry. You can treat it as a normal Ruby file