Skip to content

Instantly share code, notes, and snippets.

View jacobsimeon's full-sized avatar

Jacob Morris jacobsimeon

  • Mozilla/Pocket
  • Vancouver, WA
View GitHub Profile
@jacobsimeon
jacobsimeon / remove_all_gems.rb
Created July 31, 2011 22:25
For some reason, sometimes you just want to delete your gems and start over.
`gem list --no-versions`.split("\n").each do |gem|
`gem list -d #{gem}`.gsub(/Installed at(.*):.*/).each do |dir|
dir = dir.gsub(/Installed at(.*): /,'').gsub("\n", '')
system "gem uninstall #{gem} -aIx -i #{dir}"
end
end
@jacobsimeon
jacobsimeon / postgres-table-info.sql
Created October 24, 2011 16:30
A handy query for getting information about tables and columns in a postgresql database.
SELECT col.attrelid::regclass as table,
col.attname as name,
format_type(col.atttypid, col.atttypmod) as type,
col.attnotnull as not_null,
def.adsrc as default,
( SELECT d.refobjid
FROM pg_depend d
WHERE col.attrelid = d.refobjid
AND col.attnum = d.refobjsubid
LIMIT 1
@jacobsimeon
jacobsimeon / setup_load_paths.rb
Created December 7, 2011 02:41
Tell phusion passenger how to use rvm gemsets
# include this file in <RAILS_ROOT>/config
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
@jacobsimeon
jacobsimeon / .bash_profile
Last active September 28, 2015 13:37
My bash profile.
alias rr='touch tmp/restart.txt'
alias apache_logs='cd /private/var/log/apache2/'
alias vhosts='vim /private/etc/apache2/users/jacob.conf'
alias hosts='vim /etc/hosts'
alias profile='vim ~/.bash_profile'
alias apache='sudo apachectl'
alias mongo_start='mongod run --config /usr/local/Cellar/mongodb/1.6.3-x86_64/mongod.conf'
alias cleardns='dscacheutil -flushcache'
alias grma='git ls-files --deleted -z | xargs -0 git rm'
alias cleanswap='find . | grep .swp | xargs rm'
@jacobsimeon
jacobsimeon / count_lines.rb
Created December 29, 2011 01:58
Count the number of lines in the specified pattern
root_dir = ARGV[0] || "."
ext = ARGV[1] || "rb"
pattern = "#{root_dir}/**/*.#{ext}"
puts "Counting lines in files which match: #{pattern}"
count = 0
Dir[pattern].each do |file|
lines_in_file = 0
if File.exists? file
contents = File.read(file).split("\n")
@jacobsimeon
jacobsimeon / mortgage_calculator.js
Created March 28, 2012 23:52
Mortgage_calculator
var calculate_payment = function(loan_amount, interest_rate){
var _rate = interest_rate / 1200;
var pi = ( _rate + (_rate / (Math.pow((1 + _rate), 360) - 1) ) ) * loan_amount;
var taxes = (loan_amount * 0.01) / 12;
var ins = 40;
var mi = (loan_amount * 0.0125) / 12;
return pi + taxes + ins + mi;
}
for(var i = 120; i <= 160; i++){
@jacobsimeon
jacobsimeon / shorten.js
Created April 18, 2012 20:28
Send a request to a remote server and show the response in a modal dialog.
var shorten = function(){
var frame = document.createElement('iframe');
var body = document.body;
var location = document.location;
var url = "";
if (!body) {
document.alert("Unable to shorten the url, try again after the page finishes loading");
return;
}
@jacobsimeon
jacobsimeon / QueryableExtensions.cs
Created July 12, 2012 01:05
IQueryable Extensions for ordering by a property specified by a string
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace JacobSimeon.Extensions
{
public static class IQueryableExtensions
@jacobsimeon
jacobsimeon / password_complexity.rb
Created August 21, 2012 21:38
Password Complexity
# Regular expression to require the following
# Thanks to Scott Chamberlain on Stack Overflow
# http://stackoverflow.com/questions/3721843
# All ASCII printing characters
# At least 8 characters in length
# At least 1 lowercase letter
# At least 1 uppercase letter
# At least 1 special character
# No white-space characters
# At least 1 number
@jacobsimeon
jacobsimeon / References.sql
Created August 28, 2012 16:18
List tables with foreign key that references a given table
select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'PriorAuthorizationRequests')
order by TableWithForeignKey, FK_PartNo