Skip to content

Instantly share code, notes, and snippets.

# http://adventofcode.com/day/3 - part 1
#
# instructions - String with sequentials commands for which direction to take.
# ^ north, v south, > east, < west
#
# Returns an integer of the area of wrapping paper required, in square feet.
def houses_visited_by_santa(instructions):
visited = [[0, 0]]
x = y = 0
# http://adventofcode.com/day/2
defmodule AdventDay2 do
# Part 1
#
# present_dimensions - String a list of present dimensions, each in the format of
# 1x2x3 where 1 is the length, 2 is the width and 3 is the height,
# in feet.
#
# Returns an integer of the area of wrapping paper required, in square feet.
def required_wrapping_paper(present_dimensions) do
// http://adventofcode.com/day/1 - part 1
//
// instructions - String containing coded instructions for moving up a floor with
// "(" and down a floor with ")"
// Starting ground floor numbered zero is assumed.
// Returns an integer value for the expected floor.
func upsAndDowns(instructions: String) -> Int {
var floor: Int = 0
for character in instructions.characters {
# http://adventofcode.com/day/3 - part 1
#
# instructions - String with sequentials commands for which direction to take.
# ^ north, v south, > east, < west
#
# Returns an integer of the area of wrapping paper required, in square feet.
def houses_visited(instructions)
visited = [[0, 0]]
x = 0
# http://adventofcode.com/day/2 - part 1
#
# present_dimensions - String a list of present dimensions, each in the format of
# 1x2x3 where 1 is the length, 2 is the width and 3 is the height,
# in feet.
#
# Returns an integer of the area of wrapping paper required, in square feet.
def required_wrapping_paper(present_dimensions)
total_area = 0
# http://adventofcode.com/day/1 - part 1
#
# instructions - String containing coded instructions for moving up a floor with
# "(" and down a floor with ")"
# Starting ground floor numbered zero is assumed.
#
# Returns an integer value for the expected floor.
def ups_and_downs(instructions)
instructions.count("(") - instructions.count(")")
end
@boone
boone / pcomplete.sh
Created November 24, 2015 03:28
Get an email notification when a process completes
#!/bin/bash
# Watch a running process and notify by email when it's done
# usage ./pcomplete.sh pid email
# or nohup ./pcomplete.sh pid email & to background it
# TODO verify args
# TODO timeout option
# TODO include abiity to detach and run in the background
@boone
boone / fix_sql_injection.rb
Created June 13, 2012 03:42
Monkey patch for CVE-2012-2695 on Rails 2.3.14
# Monkey patch for CVE-2012-2695 on Rails 2.3.14
# put this file in your config/initializers directory
# comments/corrections: https://gist.github.com/2921706
# Ruby on Rails SQL Injection
# based on a patch from @presidentbeef
# https://rubyonrails-security.googlegroups.com/attach/aee3413fb038bf56/2-3-sql-injection.patch?view=1&part=3
module ActiveRecord
class Base
@boone
boone / strip_nil_from_parameters.rb
Created June 1, 2012 18:08
Monkey patch for CVE-2012-2660 and CVE-2012-2694 on Rails 2.3.14
# Monkey patch for CVE-2012-2660 and CVE-2012-2694 on Rails 2.3.14
# put this file in your config/initializers directory
# comments/corrections: https://gist.github.com/2854095
# Strip [nil] from parameters hash
# based on a pull request from @sebbacon
# https://github.com/rails/rails/pull/6580
module ActionController
class Request < Rack::Request
@boone
boone / hash_copy.rb
Created June 6, 2011 19:27
Ruby unexpected behavior when using .clone or .dup on a hash (or array)
# Ruby unexpected behavior when using .clone or .dup on a hash (or array)
# create a hash and freeze it so it shouldn't be modified
MY_HASH = { :one => { :first => 'eins', :second => 'zwei' } }.freeze
puts MY_HASH.inspect # {:one=>{:first=>"eins", :second=>"zwei"}}
new_hash = MY_HASH.dup # copy the hash, unfrozen
new_hash[:one][:second] = 'dos'