Skip to content

Instantly share code, notes, and snippets.

View danman01's full-sized avatar

Danny Kirschner danman01

View GitHub Profile
@danman01
danman01 / unicorn.rb
Last active December 20, 2015 17:09
unicorn.rb for a ec2 micro instance
worker_processes 2
working_directory "/var/www/apps/myapp/current"
preload_app true
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
end
timeout 70
# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
@danman01
danman01 / manage-staging.sh
Created August 9, 2013 17:52
toggle your staging amazon ec2 instance when you run the script
#!/bin/bash
# make sure to have amazon ec2 command line tools installed
# this script assumes have an elastic ip, and the instance id is static
# enter your settings here
STAGING="instance-id"
STAGING_IP="your elastic ip"
# get the status if your instance
STATUS=`ec2-describe-instances $STAGING | awk 'FNR == 2 {print $6}'`
@danman01
danman01 / Capistrano-unicorn avoid duplicate processes.md
Last active January 4, 2016 15:29
Avoid already running / unable to listen errors while using capistrano-unicorn with monit / God / upstart scripts

Make sure that your init.d or upstart scripts to manage Unicorn and its workers are taken into account when capistrano-unicorn is doing the unicorn restart / reload / duplication tasks.

I did not think to look at these scripts when I had to debug the stale pid file / already running / unable to listen on socket errors. But it makes sense, as upstart starts Unicorn when it is not running, and then capistrano-unicorn is also attempting to start Unicorn.

I combine these capistrano tasks and hooks with Monit and a Unicorn init script.

Capistrano tasks:

namespace :monit do
@danman01
danman01 / gist:8806315
Last active August 29, 2015 13:56
spree_heroku_errors.md

Here's some errors I ran into:

I am getting nil country.states error when at checkout/address. I tried to dig around in the code, but haven't gotten too far. I do have a default country ID set, so maybe my default @order.address is nil...I will need to debug further. Again, this is with a fresh postgresql database.

(Also, where is checkout#edit action? There's a lot of modules to dig into and I haven't been able to find it. If I find the edit action, I would throw a debugger in there to see what my @order has)

So that was all on heroku (https://partsomobile.herokuapp.com/).

I felt I should have been testing locally first, so I started my server and I added a product called mug, but do not see where I specify quantity available.

@danman01
danman01 / pull.js
Created April 21, 2014 18:31
remove single item from array in javascript
/* Removes first specified item from array, if it exists
Use like: ["55","35"].pull("35")
Handles cases where "35" isn't in the array
Modifies array and returns pulled item
*/
Array.prototype.pull = function(x) {
var index = this.indexOf(x);
var to_return = undefined;
if(index !== -1) {
this.splice(index, 1);
@danman01
danman01 / fix_dropbox.sh
Created April 24, 2014 15:54
fix bad dropbox backup
#make a backup of your repo if you aren't sure about this one, because these commands are irreversible.
#first, go to your repos directory.
cd myrepo
#then recursively search for the conflicted files and delete them
find . -type f -name "* conflicted copy*" -exec rm -f {} \;
#lastly, remove any "conflicted" references from git's packed-refs file
@danman01
danman01 / upgrade-ruby-rvm-passenger-nginx-debian.sh
Created April 26, 2014 19:07
passenger upgrade ruby debian
#ssh into the server and:
rvm get stable
rvm get head
rvm install ruby-version-that-you-want
rvm gemset use rubyversion@gemset --create
#locally:
#update local version
bundle install
#capfile is set to pull from local version when deploying
@danman01
danman01 / batchbook_curl_post_api.md
Last active August 29, 2015 14:03
Batchbook curl post to api

Use the following curl command to POST xml data to the Batchbook api people endpoint. This will create a new Person contact in the apitest account.

curl -X POST -H "Content-Type: text/xml" -d "xml-string-data" "url"

where "xml-string-data" is something like:

<?xml version='1.0' encoding='UTF-8'?> <person> <about nil='true'/><champion type='boolean'>false</champion> <first-name>MyXml</first-name> <last-name>ApiTest</last-name> <middle-name nil='true'/> <name nil='true'/> <prefix nil='true'/> </person>
@danman01
danman01 / postmark.txt
Created July 31, 2014 19:48
postmark inbound json response
Processing by BatchboxController#create as JSON
Parameters: {"FromName"=>"Danny K", "From"=>"[email protected]", "FromFull"=>{"Email"=>"[email protected]", "Name"=>"Danny K", "MailboxHash"=>""}, "To"=>"[email protected], \"Danny Kirschner\" <[email protected]>", "ToFull"=>[{"Email"=>"[email protected]", "Name"=>"", "MailboxHash"=>""}, {"Email"=>"[email protected]", "Name"=>"Danny Kirschner", "MailboxHash"=>""}], "Cc"=>"", "CcFull"=>nil, "Bcc"=>"", "BccFull"=>nil, "Subject"=>"test csv", "MessageID"=>"3187dfc1-5245-4ece-94b0-343126a8d177", "ReplyTo"=>"", "MailboxHash"=>"", "Date"=>"Thu, 31 Jul 2014 15:16:46 -0400", "TextBody"=>"testing csv to ngrok\r\n", "HtmlBody"=>"&lt;div dir=&quot;ltr&quot;&gt;testing csv to ngrok&lt;/div&gt;\r\n", "StrippedTextReply"=>"", "Tag"=>"", "Headers"=>[{"Name"=>"X-Spam-Checker-Version", "Value"=>"SpamAssassin 3.3.1 (2010-03-16) on sc-ord-inbound2"}, {"Name"=>"X-Spam-Status",
@danman01
danman01 / git_setup.txt
Created September 1, 2014 00:30
setting up git
some nice things to do when setting up git:
# just push current branch when you do git push:
git config --global push.default current