Skip to content

Instantly share code, notes, and snippets.

View millisami's full-sized avatar
🎯
Focusing on landing a Web3 Job

Sachin Sagar Rai millisami

🎯
Focusing on landing a Web3 Job
View GitHub Profile
@millisami
millisami / add_lvhme.sh
Created December 18, 2016 09:34 — forked from mdespuits/add_lvhme.sh
Add lvh.me to Mac OS X hosts file
#!/bin/bash
main() {
if [[ $(has_lvh_me) == 1 ]]; then
echo 'lvh.me is already specified in your hosts file'
else
add_lvh_me
echo 'lvh.me was added to your hosts file!'
fi
flush_dns_cache
@millisami
millisami / wp-theme-review-setup.sh
Created December 13, 2016 09:47
Scaffold a new WordPress site using an Alfred workflow and WP-CLI. Development sites are spun up using Laravel Valet and a parked Sites folder in the root.
# Parse query name into theme and version variables (e.g. theme-name 1.0.0)
read theme version <<< "{query}"
# Create directory for new site
cd ~/Sites
mkdir $theme
cd $theme
# Download latest version of WordPress
wp core download
env = require 'config/environment'
if env.isDevelopment()
window.App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'http://localhost:3000'
})
else if env.isTest()
window.App.ApplicationAdapter = DS.FixtureAdapter.extend({
simulateRemoteResponse: false
})

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file:

# Today's little useless tidbit converts a url's query string into a hash
# set of k/v pairs in a way that merges duplicates and massages empty
# querystring values
def qs_to_hash(query_string)
keyvals = query_string.split('&').inject({}) do |result, q|
k,v = q.split('=')
if !v.nil?
result.merge({k => v})
elsif !result.key?(k)
#!/bin/sh
# ====================================================================
# This is the tmux configuration I use for setting up my Ruby on Rails
# Tutorial session
#
BASE="$HOME/sites/sample_app"
cd $BASE
tmux start-server
if Rails.env.development?
module Dragonfly
module DataStorage
class FileDataStore
def retrieve(relative_path)
validate_uid!(relative_path)
path = absolute(relative_path)
pathname = Pathname.new(path)
if !pathname.exist?
Gem versions are important due to dependency pinning problems w/ Berkshelf, Chef, and Vagrant
circa March 15th, 2013.
The older version of chef won't impact the version of chef that gets provisioned on your vagrant
box, it's just for loading the knife.rb configuration.
Use bundle exec if you want these things to operate together correctly.
$ bundle exec vagrant up solo
$ bundle exec berks upload
etc...
bash -c '
echo <%= @config[:chef_node_name] %> > /tmp/chef_node_name
cat /tmp/chef_node_name | cut -d. -f1 > /tmp/proper_hostname
cat /tmp/chef_node_name | cut -d. -f2 | tr -d "\n" > /tmp/proper_dnsdomainname
echo -n "." >> /tmp/proper_dnsdomainname
cat /tmp/chef_node_name | cut -d. -f3 >> /tmp/proper_dnsdomainname
IPV4ADDR=`ip addr | grep eth0 | grep "inet " | cut -d " " -f 6 | cut -d \/ -f 1`