Skip to content

Instantly share code, notes, and snippets.

View carpeliam's full-sized avatar
👋
say hi!

Liam Morley carpeliam

👋
say hi!
View GitHub Profile
@carpeliam
carpeliam / progress_bar.rb
Created July 14, 2015 15:56
Ruby console progress bar
def progress_bar(current, total, width=80)
pos = (current.to_f / total * width).round
print "\r|#{'=' * pos}#{'-' * (width - pos)}|"
puts if current == total
end

Keybase proof

I hereby claim:

  • I am carpeliam on github.
  • I am carpeliam (https://keybase.io/carpeliam) on keybase.
  • I have a public key ASCaBaC8yV-Z-VIp5vDtbnw64YJ6UYl83SVwk-1gnCaieAo

To claim this, I am signing this object:

@carpeliam
carpeliam / get_prisons.rb
Created January 27, 2015 05:33
Inmate Prison Locator
#!/usr/bin/env ruby
require 'spreadsheet'
require 'capybara'
require 'csv'
include Capybara::DSL
COL_CDCR = 0
@carpeliam
carpeliam / SassMeister-input-HTML.html
Last active August 29, 2015 14:14
Basic Bootstrap SASS editor to be used with sassmeister.com's bookmarklet
<link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,600,700" media="all" rel="stylesheet">
<h1>This is H1 Text</h1>
<h2>This is H2 Text</h2>
<h3>This is H3 Text</h3>
<h4>This is H4 Text</h4>
<h5>This is H5 Text</h5>
<h6>This is H6 Text</h6>
<hr>
@carpeliam
carpeliam / pre-commit
Last active August 29, 2015 14:06 — forked from eedrummer/pre-commit
#!/bin/sh
#
# To enable this hook, rename this file to "pre-commit".
PRY_PATTERN="require.+[\'\"]pry[\'\"]|binding\.pry"
# Redirect output to stderr.
exec 1>&2
if git diff --cached | grep '^\+' | grep -q -E $PRY_PATTERN; then
echo "ERROR: There is left over pry stuff in this commit"
@carpeliam
carpeliam / gist:08fad4f02e1d3fa2ef23
Last active August 29, 2015 13:58
This is how to get patient summary details from a node console, similar to the function call at https://github.com/robtweed/ewdGateway2/blob/master/ewdLite/node_modules/VistADemo.js#L81.
// after running `vagrant ssh` to log into VM:
// sudo su - osehra
// cd ewdjs
var ewdGlobals = require('ewdjs/lib/ewdGlobals');
var interface = require('nodem/lib/mumps');
var db = new interface.Gtm();
var util = require('util');
var ok = db.open();
ewdGlobals.init(db);
@carpeliam
carpeliam / ruby-warrior.rb
Created July 28, 2013 20:12
My code for the final level at https://www.bloc.io/ruby-warrior. Could have been more efficient (pivot earlier when the closest object is a wall, don't bother healing when there are no enemies left) but I'm happy enough with it.
class Player
def play_turn(warrior)
@health ||= warrior.health
taking_damage = warrior.health < @health
objects = warrior.look
closest_enemy = objects.detect { |s| s.enemy? }
closest_captive = objects.detect { |s| s.captive? }
enemy_is_closer = closest_captive && closest_enemy && objects.index(closest_enemy) < objects.index(closest_captive)
class Cell
attr_accessor :is_mine, :num_adjacent_mines
def initialize
self.num_adjacent_mines = 0
end
def to_s
if is_mine
'*'
else
Parent extends Backbone.Model
initialize: ->
# should the model listen to child events here and fire a separate event?
@children = new Backbone.Collection([], model: Parent)
ObjView extends Backbone.View
initialize: ->
@collection = new Backbone.Collection([], model: Parent)
# should the view try to be responsible for listening to any sync on any child, no matter how deep?
@collection.each (m) ->
@carpeliam
carpeliam / .irbrc.rb
Created March 24, 2012 22:42
pretty print active record model (good for .irbrc)
def arp(model)
key_length = model.attributes.keys.max_by(&:size).size
model.attributes.sort.each do |k,v|
puts "#{k.ljust key_length}: #{v.inspect}"
end
return nil
end