Skip to content

Instantly share code, notes, and snippets.

View cbartlett's full-sized avatar

Colin Bartlett cbartlett

View GitHub Profile
def check_grade(grade)
puts "Checking #{grade}"
case grade
when 90..100
puts "A"
when 80...90
puts "B"
else
puts "loser"
end
@cbartlett
cbartlett / info.plist
Created October 13, 2015 23:55 — forked from mlynch/info.plist
Disable App Transport Security in iOS 9
<!--
This disables app transport security and allows non-HTTPS requests.
Note: it is not recommended to use non-HTTPS requests for sensitive data. A better
approach is to fix the non-secure resources. However, this patch will work in a pinch.
To apply the fix in your Ionic/Cordova app, edit the file located here:
platforms/ios/MyApp/MyApp-Info.plist
And add this XML right before the end of the file inside of the last </dict> entry:
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR
# make database backup
#!/usr/bin/env ruby
require 'json'
if ARGV.length < 3 then
puts "Usage: squirt <filename> <channel> <comment>"
exit
end
token = ENV['TOKEN'] || ""
@cbartlett
cbartlett / average_deploy.rb
Created April 16, 2015 15:42
How often do you deploy to Heroku?
#!/usr/bin/env ruby
# Copyright 2015 Colin Bartlett, Inc.
# MIT Licensed: http://opensource.org/licenses/MIT
# Usage: ./average_deploy.rb your-heroku-app-name
require 'time'
dates = `heroku releases -n 50 -a #{ARGV[0]} | grep Deploy`
Error detected while processing User Auto commands for "ProjectionistDetect":
E716: Key not present in Dictionary: rake_command('static'))}}) | endif
E116: Invalid arguments for function split(rails#app().rake_command('static'))}}) | endif
E116: Invalid arguments for function projectionist#append
UpdateLastColumn failed to find bufnr 9 in w:BufKillList
UpdateLastColumn failed to find bufnr 9 in w:BufKillList
@cbartlett
cbartlett / gist:7d2f027650ed0e74cbd3
Created November 11, 2014 16:36
removes orphaned records
model_base = Rails.root.join('app/models')
Dir[model_base.join('**/*.rb').to_s].each do |filename|
# get namespaces based on dir name
namespaces = (File.dirname(filename)[model_base.to_s.size+1..-1] || '').split('/').map{|d| d.camelize}.join('::')
# skip concerns folder
next if namespaces == "Concerns"
require 'spec_helper'
describe Event do
let(:event) { FactoryGirl.create(:event) }
let(:summer_long_event) { FactoryGirl.create(:summer_long) }
describe '.summer_long' do
subject { described_class.summer_long }
it { should include(summer_long_event) }
it { should_not include(event) }
#!/bin/bash
clean()
{
REMOTES="$@";
if [ -z "$REMOTES" ]; then
REMOTES=$(git remote);
fi
REMOTES=$(echo "$REMOTES" | xargs -n1 echo)
RBRANCHES=()
@cbartlett
cbartlett / gist:2093abd42296ddd51775
Last active December 22, 2023 09:26
Print Ruby Exception Hierarchy
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
end