Skip to content

Instantly share code, notes, and snippets.

View shannonwells's full-sized avatar
🦞
Not being hasty

Shannon Wells shannonwells

🦞
Not being hasty
View GitHub Profile
@shannonwells
shannonwells / rspec_snippets.rb
Last active August 29, 2015 13:55
My favorite rspec snippets
# Sanity tests for factories and persistence in db
# Makes sure you have not inadvertently hosed validation, and suchlike when models are changed
shared_examples_for 'a model' do |factory, factory_params = {}|
let(:model) { FactoryGirl.build(factory, factory_params) }
it 'can be persisted' do
expect(model).to be_valid
model.save!
expect(model).to be_persisted
end
@shannonwells
shannonwells / bash_profile
Last active January 12, 2019 00:10
bash profile
cat ~/.bash_profile
export EDITOR=vim
export CLICOLOR=1
export PS1="\[\033[34m\]\h:\W \[\033[35m\]\$(parse_git_branch)\[\033[00m\]\$(git config user.initials)$\[\033[00m\] "
export SUDO_PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[0;31m\]\$ \[\e[0m\]'
export HISTCONTROL=ignoredups;
shopt -s histappend;
export PROMPT_COMMAND='echo -ne "\033]0;${USER}: ${PWD}\007"'
@shannonwells
shannonwells / socksify_faraday.rb
Last active May 7, 2021 20:52
Faraday + SOCKS
require 'rubygems'
require 'faraday'
require 'socksify'
require 'socksify/http'
require 'awesome_print'
# This is a SOCKS monkey patch for Faraday, with example use/unit test.
# Notes:
# * It is altered to work with SOCKS5 authentication.
# * net_http_class must return a Faraday::Adapter::NetHttp instance.
@shannonwells
shannonwells / myclass_base.rb
Created October 8, 2014 23:33
How to set up using a different database in rails from the default
class MyclassBase < ActiveRecord::Base
self.abstract_class = true
CONFIG_PATH = File.join(Rails.root, 'config', 'database_myclass.yml') unless defined? CONFIG_PATH
# So you can use environment variables in your YML file.
erb = ERB.new(File.read(CONFIG_PATH)).result
config = ActiveSupport::HashWithIndifferentAccess.new(YAML.load(erb))[Rails.env]
raise ConfigurationNotFound.new("Configuration not found for config_path: '#{CONFIG_PATH}'") unless config
@shannonwells
shannonwells / tiny_tds_ports.rake
Last active August 29, 2015 14:10
This is an annotated ports.rake file for compiling platform-specific gems of tiny_tds for OS X and linux,statically linked with a custom build of freetds with openssl. Please use the tiny_tds_extconf.rb file if you want this to work as such.
require 'mini_portile'
# All my notes are tagged with --shannonwells.
# I was able to compile platform-specfic gems on OS X Mavericks, AWS-linux AMI and AWS ubuntu AMI.
# Please feel free to pm me here or on Twitter (@shannonewells) if you want help --shannonwells
# If you're using 0.82, you may have to make a conf file to get it to work. For example:
# $ export FREETDSCONF='/opt/local/etc/freetds/freetds.conf'
ICONV_VERSION = "1.14"
@shannonwells
shannonwells / tiny_tds_extconf.rb
Last active August 29, 2015 14:10
This is an edited and annotated tiny_tds extconf.rb with changes needed to get tiny_tds to build as a platform-specific linux gem, statically linked with a custom build of freetds with openssl. It is intended to allow encrypted connections with MS SQL Server. Please use the tiny_tds_ports.rake Gist or else this code will not work.
ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
# :stopdoc:
require 'mkmf'
# Shamelessly copied from nokogiri
#
# All my notes are tagged with --shannonwells.
@shannonwells
shannonwells / search_for_columns
Last active January 15, 2016 23:17
SQLServer: Search for columns throughout an entire db which match a given substring.
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%sometext%'
ORDER BY schema_name, table_name;
@shannonwells
shannonwells / glacier-up.sh
Last active November 11, 2015 23:40
A short script illustrating how to upload items to AWS Glacier. Also includes how to split them up before uploading. Intended for occasional use.
#!/bin/bash
# This script assumes you have already installed the AWS CLI tools and the treehash Ruby gem.
VAULT=MyVaultName # AWS Glacier vault name
ACCOUNT=123456890 # AWS Account number
DIR=$HOME/mydir
TREEHASH=/Users/fair/.rvm/gems/ruby-2.2.1/bin/treehash
@shannonwells
shannonwells / sphere.rb
Last active April 18, 2016 16:56
A Sphere class that can give you random, uniformly distributed coordinates on the surface of a sphere. Default creates a unit sphere. You can set the sphere's radius directly or set it by its known volume ("Assume a spherical cow...")
# https://www.jasondavies.com/maps/random-points/
require 'rspec'
require 'awesome_print'
class Sphere
attr_accessor :radius, :units
def initialize(radius=1.0)
srand

Keybase proof

I hereby claim:

  • I am shannonwells on github.
  • I am squeedle (https://keybase.io/squeedle) on keybase.
  • I have a public key whose fingerprint is 2808 B806 5FDF 578E BB4C 7787 D45A 500A D1C7 74F1

To claim this, I am signing this object: