Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Mervine jmervine

View GitHub Profile
View gitwho.sh
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"
View gitconfig
[color]
ui = true
[user]
name = <name>
email = <email>
[core]
editor = vim
View .gitignore
.bundle
.*.sw*
.DS_Store
.yardoc
View array_to_h.rb
class Array
def to_h(keys)
Hash[*keys.zip(self).flatten]
end
end
@jmervine
jmervine / simpleimapreader.rb
Created Nov 4, 2011
module SimpleImapReader
View simpleimapreader.rb
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 Mar 16, 2012
Rails: Dynamic Model from JSON sans DB
View gist:2052468
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 Mar 16, 2012
Ruby: dynamically generated object with accessors
View gist:2052509
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 Mar 18, 2012
Sample Nginx Proxy Configuration
View gist:2067951
$ sudo cat /etc/nginx/sites-enabled/blog
server {
server_name blog.mervine.net;
location / {
proxy_pass http://f2h1gg.tumblr.com;
}
}
View update_ruby_version_ubuntu.sh
#
# 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 Mar 18, 2012
installing mysql on ubuntu using an aws instance
View gist:2079897
$ 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;