Skip to content

Instantly share code, notes, and snippets.

View mariusbutuc's full-sized avatar
🌏

Marius Butuc mariusbutuc

🌏
  • Toronto, ON
  • 00:52 (UTC -04:00)
View GitHub Profile
@mariusbutuc
mariusbutuc / 3_mars_rover.rb
Last active April 22, 2016 22:31 — forked from nickhoffman/rover.rb
Mars Rover code kata
class Rover
class InvalidDirection < StandardError
def message
'Vertigoooooo!'
end
end
VALID_DIRECTIONS = %i(north south east west).freeze
attr_accessor :ns_coordinates, :ew_coordinates, :direction
@mariusbutuc
mariusbutuc / test_helper.rb
Last active March 14, 2016 14:27 — forked from arax/gist:4226541
VCR - ignore specific requests
# …
VCR.configure do |c|
c.hook_into :webmock
c.cassette_library_dir = 'spec/cassettes'
c.default_cassette_options = { :record => :new_episodes }
## Ignore some requests based on the hosts involved.
c.ignore_hosts 'localhost', '8.8.8.8', 'our.local.test.server.org'
@mariusbutuc
mariusbutuc / test_with_cassette.rb
Last active October 7, 2015 19:18 — forked from jrochkind/example.rb
MiniTest and VCR: one cassette per test?
module TestWithCassette
# cribbed from Rails and modified for VCR
# https://github.com/rails/rails/blob/b451de0d6de4df6bc66b274cec73b919f823d5ae/activesupport/lib/active_support/testing/declarative.rb#L9
def test_with_cassette(name, vcr_options = {}, &block)
auto_cassette_name = name.gsub(/\s+/, '_')
test_name = "test_#{auto_cassette_name}".to_sym
if block_given?
group = vcr_options.delete(:group)
group_prefix = "#{group}/" if group.present?
#!/usr/bin/env ruby
require 'csv'
require 'json'
if ARGV.size != 2
puts 'Usage: csv_to_json input_file.csv output_file.json'
puts 'This script uses the first line of the csv file as the keys for the JSON properties of the objects'
exit(1)
end
@mariusbutuc
mariusbutuc / pg_upgrade.sh
Last active August 29, 2015 14:17 — forked from joho/gist:3735740
PostgreSQL 9.3 to 9.4.1 upgrade steps
# Steps to install and run PostgreSQL 9.4.1 using Homebrew (Mac OS X)
# (if you aren't using version 9.3, change line #9 with the correct version)
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres93
brew update
brew upgrade postgresql
initdb /usr/local/var/postgres -E utf8
pg_upgrade -b /usr/local/Cellar/postgresql/9.3/bin -B /usr/local/Cellar/postgresql/9.4.1/bin -d /usr/local/var/postgres93 -D /usr/local/var/postgres
cp /usr/local/Cellar/postgresql/9.4.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
@mariusbutuc
mariusbutuc / git_rename_branch.sh
Last active August 29, 2015 14:17 — forked from stuart11n/gist:9628955
Rename git branch—both locally and upstream.
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
require 'digest'
# Get SHA256 Hash of a file
puts Digest::SHA256.hexdigest File.read "data.dat"
# Get MD5 Hash of a file
puts Digest::MD5.hexdigest File.read "data.dat"
# Get MD5 Hash of a string
puts Digest::SHA256.hexdigest "Hello World"
# Get SHA256 Hash of a string using update

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <[email protected]>
# Copyright:: 2007-2010 The Authors
@mariusbutuc
mariusbutuc / chef_solo_bootstrap.sh
Last active December 14, 2015 05:58 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
# Apt-install various things necessary for Ruby etc.,
# and remove optional things to trim down the machine.
apt-get -y update
apt-get -y upgrade
apt-get -y install linux-headers-$(uname -r) build-essential
apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev
apt-get -y install vim
apt-get -y install git-core