This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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_by_santa(instructions): | |
visited = [[0, 0]] | |
x = y = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |