Skip to content

Instantly share code, notes, and snippets.

View schowdhury's full-sized avatar

Sameer Chowdhury schowdhury

View GitHub Profile
@schowdhury
schowdhury / textmate_rvm.sh
Created July 12, 2011 16:16
Using textmate with rvm
#generate a wrapper script for a textmate_ruby - you can call it whatever you like but
#textmate_ruby is clear
rvm wrapper ruby-1.9.2@rails3 textmate
# this will generate a textmate_ruby command for you
# problem with the above is, it's not going use your project specific gemset and ruby
# to do that, edit the file and change the contents to what's below
@schowdhury
schowdhury / gist:1029563
Created June 16, 2011 15:56
talking REST with json payload... first curl and then activeresource
#Please excuse the naming of things, this is a on the fly contrived example
curl -i -H "Content-Type: application/json" -H "Accept: application/json"
-X POST -d '{"a_request":{"thing_ids":[1,2,3,4]}}' http://localhost:3000/a_requests
produces....
Started POST "/a_requests" for 127.0.0.1 at 2011-06-16 11:53:21 -0400
Processing by ARequests#create as JSON
@schowdhury
schowdhury / gist:1017462
Created June 9, 2011 19:07
vanilla ruby class with list of activerecord objects integrates with rails form helpers
#I want to create many of a thing in one shot where thing is an activerecord class with
#validations. I can use the following where a listofthings is a vanilla ruby class. on
#valid? this class calls all the contained object's valid? method. and a naive save that
#calls save on each of the contained activerecord objects. There's some syntatic sugar,
#methods that hide the underlying list. This is minimal code for explanation.
#My thing is an activerecord class
#ListOfMyThings is a vanilla ruby class
#thing to note for form helpers to work you need
# _attributes=(attributes) method defined.
@schowdhury
schowdhury / google map rails integration
Created June 9, 2011 18:55
Get google maps integrated with your app -minimal code
#------ application layout
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
<%= javascript_include_tag "jquery", "jquery-ui","rails" %>
<%= javascript_include_tag "application" %>
.....
<script type="text/javascript">
<%= yield(:javascript)%>
</script>
@schowdhury
schowdhury / deploying with rvm and standalone passenger
Created March 29, 2011 19:29
general deploy script that works with rvm and standalone passenger adding custom variables from 2 scripts
set :application, 'myapp'
set :repository, "git@github.com:me/myapp.git"
set :deploy_to, "/var/www/rails/#{application}"
set :rake, 'rake'
# This change was done enable the ability to deploy a branch to
# staging using the parameters on the command line.
# to deploy mobile, $> cap -S branchto=mobile staging deploy
# to deploy master by default, $> cap staging deploy
begin
@schowdhury
schowdhury / chef
Created March 24, 2011 19:46
chef misc...
client: knife cookbook upload apache2 # will upload to opscode servers
server: chef-client # to pull changes from opscode servers
@schowdhury
schowdhury / gist:881361
Created March 22, 2011 15:04
Following is my Rails 3 box setup, soon to be captured into a chef recipie
Rails 3 box setup - on centos
Note, the $ indicates a command prompt on your terminal
----- Firewall -----
make sure you can install packages through yum, have access to github.com: http, git (port 9418), ssh and https
Make sure the following ports are accessible to you: http, https and ssh
------- System packages -------------
@schowdhury
schowdhury / gist:881346
Created March 22, 2011 14:58
rails caching with apache enable through rewrite rules
I generate all my page caching in public/cache directory. The following apache rewrite rules check cache before hitting the rails app
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{REQUEST_URI} ^/([^.]+)$
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
RewriteRule ^/[^.]+$ /cache/%1.html [QSA,L]
@schowdhury
schowdhury / gist:870075
Created March 14, 2011 23:30
barbones rails project with devise. enabled with cucumber/rspec/factory_girl
rails new playing_around -d mysql -T -J
# edit rmvrc file
# rvm use ruby-1.9.2@playing_around --create
gem install bundler
#add at least the following gems for cucumber and rspec testing. nifty generators are kinda cool too
#group :test, :development do
# gem 'cucumber-rails'
@schowdhury
schowdhury / passenger3 standalone set environment variables
Created October 22, 2010 19:12
passenger3 standalone set environment variables rails3
Following this article:
http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
This is a system level rvm install
rvm use 1.9.1
gem install passenger --pre
cd /webapps/fries.com
passenger start -a 127.0.0.1 -p 3000 -d