Skip to content

Instantly share code, notes, and snippets.

@schacon
schacon / upload.rb
Created April 16, 2012 23:48
ruby script to upload a file to GitHub downloads section
#! /usr/bin/env ruby
#
# ruby upload.rb user pass user/repo file '(description)'
#
require 'json'
if ARGV.size < 4
puts "\nUSAGE: upload.rb [user] [pass] [user/repo] [filepath] ('description')"
exit
@schacon
schacon / get_token.sh
Created April 9, 2012 15:38
shell command to get a GitHub OAuth token
# sh get_token.sh user pass
curl -s -d '{"scopes":["repo"],"note":"admin script"}' -u "$1:$2" -XPOST https://api.github.com/authorizations | grep token
@wolph
wolph / to_json.sql
Created April 6, 2012 10:35
Some functions to convert arrays/hstore to json :)
CREATE OR REPLACE FUNCTION escape_json (text) RETURNS text AS $$
SELECT replace($1, '''', '\'''); $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(text) RETURNS text AS $$
SELECT escape_json($1) $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(KEY text, value text) RETURNS text AS $$
SELECT '''' || to_json($1) || ''': ''' || to_json($2) || ''''; $$ LANGUAGE SQL IMMUTABLE;
@mperham
mperham / convert.rake
Created March 15, 2012 17:44
Ruby script to update MySQL from Latin1 to UTF8 without data conversion
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
end
else
@nandub
nandub / gist:1381650
Created November 21, 2011 04:44
git fix merge conflicts steps
cd <PROJECT>
git remote add upstream git@github.com:<GITHUB_ACCOUNT_NAME>/<PROJECT>.git
git fetch upstream
#Stash/commit all your work
git checkout develop
git merge upstream/develop
git checkout <FEATURE_BRANCH>
git merge develop
#Fix errors, merge conflicts, etc.
#Run tests
@defunkt
defunkt / gitio
Created September 11, 2011 08:11
Turn a github.com URL into a git.io URL.
#!/usr/bin/env ruby
# Usage: gitio URL [CODE]
#
# Turns a github.com URL
# into a git.io URL
#
# Copies the git.io URL to your clipboard.
url = ARGV[0]
code = ARGV[1]
@derekcollison
derekcollison / Cloud Foundry Production Updates
Created April 16, 2011 17:11
How to update your application in Cloud Foundry without dropping user requests..
# vmc update is great for test and development, however it stops your old app and stages and starts the new one,
# resulting in dropped requests.
# If you want to update an application without dropping user requests, see below.
# NOTE: This change assumes your application can share services, etc with the new version.
# Assume my app is named foo
vmc push foo-v2 --url foov2.cloudfoundry.com
def explain!
puts 'Want to embed this Gist?'
puts 'Use this: <script src="http://gist.github.com/2059.js"></script>'
end
explain!