Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin Bartlett cbartlett

View GitHub Profile
View check.rb
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 Oct 13, 2015 — forked from mlynch/info.plist
Disable App Transport Security in iOS 9
View info.plist
<!--
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:
View dokku-pg-backup.sh
#! /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
View squirt
#!/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 Apr 16, 2015
How often do you deploy to Heroku?
View average_deploy.rb
#!/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`
View gist:51f487f475418be834c3
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
View gist:7d2f027650ed0e74cbd3
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"
View gist:1e5f540acec9ab2cb21a
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) }
View gist:ad09c2d63224fd2759c5
#!/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 Sep 19, 2020
Print Ruby Exception Hierarchy
View gist:2093abd42296ddd51775
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