Skip to content

Instantly share code, notes, and snippets.

View jmervine's full-sized avatar

Joshua Mervine jmervine

View GitHub Profile
@jmervine
jmervine / gitwho.sh
Created July 22, 2011 00:58
bash - gitwho
function gitwho() {
personal_email = "<PERSONAL_EMAIL>"
work_email = "<WORK_EMAIL>"
git_current="`git config --global --get user.email`"
if [ "$1" == "" ]; then
echo $git_current
else
if [ "$1" == "switch" ]; then
if [ "$git_current" == "$personal_email" ]; then
email="$personal_email"
@jmervine
jmervine / gitconfig
Created July 28, 2011 21:34
gitconfig
[color]
ui = true
[user]
name = <name>
email = <email>
[core]
editor = vim
@jmervine
jmervine / .gitignore
Created August 11, 2011 20:46
.gitignore
.bundle
.*.sw*
.DS_Store
.yardoc
@jmervine
jmervine / array_to_h.rb
Created August 11, 2011 21:59
Array.to_h
class Array
def to_h(keys)
Hash[*keys.zip(self).flatten]
end
end
@jmervine
jmervine / simpleimapreader.rb
Created November 4, 2011 22:32
module SimpleImapReader
module SimpleImapReader
require 'net/imap'
#require 'mail'
class << self
def config
@config ||= SimpleImapReader::Config.new
end
def configure(&block)
config.configure(&block)
@jmervine
jmervine / gist:2052468
Created March 16, 2012 20:30
Rails: Dynamic Model from JSON sans DB
require 'net/http'
class Item
#replaced with dynamic initialization below
#attr_reader :id, :user, :state
#
#
# Sample JSON
#
# [{ "id":1, "user":"john", "state":"active" },
# { "id":2, "user":"jane", "state":"inactive" },
@jmervine
jmervine / gist:2052509
Created March 16, 2012 20:37
Ruby: dynamically generated object with accessors
class Item
def initialize item
raise "expected Hash param" unless item.kind_of? Hash
item.each do |key,value|
instance_variable_set(clean_key(key), value)
define_singleton_method(key.to_s) { instance_variable_get( clean_key(key) ) }
define_singleton_method("#{key.to_s}=") { |val| instance_variable_set( clean_key(key), val ) }
end
end
@jmervine
jmervine / gist:2067951
Created March 18, 2012 02:21
Sample Nginx Proxy Configuration
$ sudo cat /etc/nginx/sites-enabled/blog
server {
server_name blog.mervine.net;
location / {
proxy_pass http://f2h1gg.tumblr.com;
}
}
#
# I've learned to never do this!
#
sudo su -
cd /etc/alternatives
mv bash_completion_gem bash_completion_gem1.8
ln -s /etc/bash_completion.d/gem1.9.1 bash_completion_gem
mv erb erb1.8
ln -s /usr/bin/erb1.9.1 erb
@jmervine
jmervine / gist:2079897
Created March 18, 2012 19:04
installing mysql on ubuntu using an aws instance
$ sudo apt-get install mysql-server mysql-client
... output omitted ...
$ sudo mysqladmin -u root -h localhost password 'password'
... output omitted ...
$ mysql -u root -p
... output omitted ...
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'your_host_name' IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;