Skip to content

Instantly share code, notes, and snippets.

View philm's full-sized avatar

Phil Misiowiec philm

View GitHub Profile
@philm
philm / gist:f7b4444b52af9ac8aba0
Created February 25, 2016 19:01
Removing stale Docker volumes
docker volume ls | cut -d' ' -f16 | xargs docker volume rm
@philm
philm / README.md
Last active February 9, 2016 18:34
How to max out CPUs via command line

When you need to simulate processor load...

Single core

cat /dev/zero > /dev/null

Multiple cores (1 2 3 4 - change as needed)

for i in 1 2 3 4; do while : ; do : ; done & done
@philm
philm / local_aliases.sh
Created March 12, 2015 15:56
Creating directory specific bash aliases
# For use case and usage notes, see https://coderwall.com/p/wvsndw/directory-specific-bash-aliases
function on_leave_dir() {
if [ -e .aliases ]; then
export OLD_ALIAS_DIR="$PWD"
fi
}
function on_enter_dir() {
if [ -n "$OLD_ALIAS_DIR" ] && ! is_subdirectory "$PWD" "$OLD_ALIAS_DIR" ; then
@philm
philm / Dockerfile
Last active June 25, 2020 11:36
Docker setup for Ruby on Rails
FROM atlashealth/ruby:2.1.2
ENV DEBIAN_FRONTEND noninteractive
# Install any dependencies needed by Rails
RUN apt-get update -q && \
apt-get install -qy curl libpq-dev libqt4-dev xvfb imagemagick --no-install-recommends && \
# install Node for asset minification
curl -sL https://deb.nodesource.com/setup | bash - && \
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
RSpec::Matchers.define :delegate do |method|
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require 'database_cleaner'
require 'email_spec'
# uncomment if you're using Sidekiq
@philm
philm / mail.rb
Created December 20, 2012 03:11
Rails mail interceptor
# config/initializers/mail.rb
ActionMailer::Base.register_interceptor(MailInterceptor) if Rails.env.staging?
@philm
philm / gist:3798197
Created September 28, 2012 06:11
TelAPI Inbound XML example
class TelapiResponsesController < ApplicationController
skip_before_filter :verify_authenticity_token
def show
xml = Telapi::InboundXml.new do
Say('Hi there', :loop => 3, :voice => 'man')
Say('Hello, my name is Sally.', :voice => 'woman')
Say('Now I will not stop talking.', :loop => 0)
end
@philm
philm / gist:1298819
Created October 19, 2011 16:22
Querystring-like string to hash via Rack::Utils and ActiveSupport
Rack::Utils.parse_nested_query("foo=bar&ale=good").symbolize_keys
# => {:ale=>"good", :foo=>"bar"}
# Compared to CGI.parse approach:
CGI.parse("foo=bar&ale=good").symbolize_keys
# => {:ale=>["good"], :foo=>["bar"]}
city = 'San Francisco'
state = 'CA'
[city, state].compact * ', '
# => 'San Francisco, CA'
city = nil
state = 'CA'
[city, state].compact * ', '
# => 'CA'