Skip to content

Instantly share code, notes, and snippets.

View bagwanpankaj's full-sized avatar

Pankaj Bagwan bagwanpankaj

View GitHub Profile
#you can copy this into IRB or just run it as a file
require "net/http"
require "uri"
url = "http://localhost:3000/login"
yaml = %{ --- !ruby/object:Time {} }
xml = %{<?xml version="1.0" encoding="UTF-8"?><foo type="yaml">#{yaml}</foo>}.strip
uri = URI.parse(url)
@bagwanpankaj
bagwanpankaj / simplified_html5_js_storage.js
Created August 17, 2012 09:58
Simplified HTML5 JS storage
app.storage = {
local: window.localStorage, // storage to be used
set: function( key, value ){
this.local.setItem( key, JSON.stringify( value ) );
$( document ).trigger( 'storage', ['set', key, value] );
},
get: function( key ){
return JSON.parse( this.local.getItem( key ) );
},
key: function( index ){
@bagwanpankaj
bagwanpankaj / html5_storage.js
Created February 8, 2012 08:43
JS HTML5 storage helper
app.storage = {
local: window.localStorage, // storage to be used
set: function( key, value ){
this.local.setItem( key, JSON.stringify( value ) );
$( document ).trigger( 'storage', ['set', key, value] );
},
get: function( key ){
return JSON.parse( this.local.getItem( key ) );
},
key: function( index ){
@bagwanpankaj
bagwanpankaj / pgDebug.js
Created August 5, 2011 09:36 — forked from purplecabbage/pgDebug.js
Workout your iPhone PhoneGap UI in Desktop Safari
var safariDebug = ( navigator.platform.indexOf("iPhone") < 0 && navigator.platform.indexOf("iPod") < 0 && navigator.platform.indexOf("iPad") < 0 );
if(safariDebug)
{
PhoneGap.run_command = function()
{
if (!PhoneGap.available || !PhoneGap.queue.ready)
return;
@bagwanpankaj
bagwanpankaj / show
Created July 22, 2011 05:49 — forked from superchink/show
This does something essentially equivalent to showoff.io if you have a publicly facing server...
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".webhostology.com"
REMOTE="$2$DOMAIN"
ssh -tR 8080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:8080 localhost"
}
@bagwanpankaj
bagwanpankaj / show.py
Created July 22, 2011 05:48 — forked from lfborjas/show.py
Tunnel a local port to a remote host (like showoff.io does)
#!/usr/bin/python
#usage python show.py <local_port>
'''
Taken from: https://gist.github.com/932137 (found in http://news.ycombinator.com/item?id=2467107 )
Let's say you have a webapp running in localhost (with `manage.py runserver` in django or `ruby script.rb` in sinatra or `rails server` or whatever) and you want others to be able to see it with a public url without deploying remotely.
ssh provides a neat facility for that: tunneling. You set up a "tunnel" from the remote host to yours and vice-versa and then you give the remote host's url and it will send all of its requests to your local daemon.
@bagwanpankaj
bagwanpankaj / factories.rb
Created July 5, 2011 08:58 — forked from technicalpickles/factories.rb
Factory Girl definition for Paperclip
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end
@bagwanpankaj
bagwanpankaj / unicorn.rb
Created July 4, 2011 02:24 — forked from defunkt/gist:206253
Uncorn config File
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@bagwanpankaj
bagwanpankaj / ruby_19_spalt_args.rb
Created February 7, 2011 18:28
Ruby 1.9 Defining Spalt arguments
We couldn’t find that file to show.
@bagwanpankaj
bagwanpankaj / ruby_19_default_args.rb
Created February 7, 2011 18:05
Ruby 1.9 Default Arguments
#rvm use 1.9.2
#ruby19 allows default arguments to be in beginning of method's arguments.
def test_default_argument(a = 1, b)
"a:#{a},b:#{b}"
end
test_default_argument(3)
#=> "a:1,b:3"