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
class Cell
attr_accessor :is_mine, :num_adjacent_mines
def initialize
self.num_adjacent_mines = 0
end
def to_s
if is_mine
'*'
else
@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)
@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 / 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 / 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 / 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

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 / 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
@carpeliam
carpeliam / projectmonitor.raptorize.js
Last active April 1, 2019 16:23
Run a raptor across the screen whenever your build is triggered.
(function() {
$.browser = {mozilla: false, webkit: false};
$('<script>').attr('src', 'https://cdn.jsdelivr.net/gh/davesierra/raptorize@master/jquery.raptorize.1.0.js').appendTo('body');
setInterval(function() {
if ($('.pipeline-graph .started').length) {
$(window).raptorize({enterOn: 'timer', delayTime: 0});
}
}, 15000);
}());
import React from 'react';
import { connect } from 'react-redux';
function fetchIfNecessary(fetchWithProps, hasRequiredProp) {
function mapDispatchToProps(dispatch, props) {
return { fetch: () => dispatch(fetchWithProps(props)) };
}
return (Component) => {
class Fetcher extends React.Component {
componentDidMount() {