Skip to content

Instantly share code, notes, and snippets.

View jah2488's full-sized avatar

Justin Herrick jah2488

View GitHub Profile
@jah2488
jah2488 / sort_fun.elm
Created January 18, 2016 21:24
Playing around with custom sorting on nested structures in Elm.
import Graphics.Element exposing (show)
type State = Ready | Working | Complete
stateSort a =
case a.state of
Ready -> 1
Working -> 2
Complete -> 3
@jah2488
jah2488 / orm_wat.rb
Created November 20, 2015 00:19
Playing around with some data-mapper-esque orm nonsense and somehow pumped out this monster.
def translate_fields(field)
mapping.invert.fetch(field.to_sym, field.to_sym)
end
def perform_query(sql, opts = {})
results = get_records_from_query(sql, opts)
columns = results.shift
results.map do |row|
model_attr_hash = Hash[
column_names.map(&method(:translate_fields)).zip([nil] * column_names.count)
@jah2488
jah2488 / 1-ruby-why-you.rb
Last active November 22, 2016 19:47
Ruby will allow you to do some pretty amazing... errr terrifying things.
class Foo
def initialize(default = case $glob
when "foo" then (def foobar; "hi!" end)
end)
@default = default
end
end
Foo.new #=> #<Foo:0x007f849f37be98 @default=nil>
$glob = 'foo'
@jah2488
jah2488 / seeing-is-believing-sublime-install.sh
Last active August 26, 2015 22:39
curl -sSL http://bit.ly/1EhquUW | bash -s 2.2.3 (Assumes you're running Sublime Text 3 on OS X with RVM)
#!/bin/sh
[ -z "$1" ] && echo "No argument supplied: Your ruby version is required" && exit 1
RUBY_VERSION=$1
PACKAGE_DIR="$HOME/Library/Application Support/Sublime Text 3/Packages/"
gem install seeing_is_believing
rvm wrapper "$RUBY_VERSION" sublime
@jah2488
jah2488 / image.md
Last active April 16, 2021 16:49
Creates a Menubar application using Node Webkit and Opal

A tiny app using opal.rb and nodewebkit to get your weather in your toolbar. so small

class ClubInfoContents
def initialize(club)
@club = club
end
def title
return "Congratulations! #{@club.name}" if @club.valid_member_count?
return @club.name
end
@jah2488
jah2488 / interesting.rb
Created April 7, 2015 17:08
If you find yourself wanting to write this code, you are probably missing an abstraction, but I like that this is possible either way.
articles.each do |article|
puts article
end.empty? and begin
puts ‘sorry, no articles’
end
@jah2488
jah2488 / map_join.md
Created March 20, 2015 05:03
I would like this

I like to manipulate data structures. Sometimes the final out put of that manipulation is a string. So I find myself using the pattern of map + join and its starting to feel like the map + flatten of old. Sadly, ruby does not have an answer for this yet, so this is what I've written in the mean time.

def map_join(arr, sep, &block)
 arr.map(&block).join(sep)
end

map_join([1, 2, 3, 4, 5], '-') { |x| x ** 2 } #=> '1-4-9-16-25'
@jah2488
jah2488 / .local.vimrc
Last active January 30, 2021 07:58
Basic VIM setup
filetype plugin indent on " Turn on plugins, auto indentation, and syntax highlighting
set nocompatible " Use Vim settings, rather then Vi settings
set nobackup " Stop vim from leaving temp files everywhere
set nowritebackup " Don't write your undo history to a file
set history=200 " Only save 200 undos
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set vb " NO BELLS!
Signal.trap(:INFO) {
puts "chill, I'm processing #@current_number"
}
@current_number = 0
loop do
@current_number += 1
sleep 3
end