Skip to content

Instantly share code, notes, and snippets.

@priyaaank
priyaaank / gist:1553788
Created January 3, 2012 06:31
Crawling SO users
require 'mongoid'
require 'mechanize'
Mongoid.load!("./mongoid.yml")
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("so_users")
end
class SOUser
include Mongoid::Document
@priyaaank
priyaaank / html_poc.js
Created January 3, 2012 18:38
JSON-P Cross Scripting
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"> </script>
<script language="javascript">
url = "http://twitter.com/status/user_timeline/priyaaank.json?count=10&callback=?"
jQuery.getJSON(url, function(data){
console.log(eval(data));
});
</script>
@priyaaank
priyaaank / Gemfile
Created January 3, 2012 19:18
Script to crawl SO User-base without using their API
source 'http://rubygems.org'
source 'http://rubyforge.org/'
gem 'mechanize'
gem "mongoid"
gem "bson_ext"
@priyaaank
priyaaank / routes.rb
Created March 31, 2012 15:36
Typical rails route file
Webapp::Application.routes.draw do
get 'home' => 'home#show'
# added for our cukes to run faster,
# in most cases circumventing the whole
# login process
if Rails.env.test?
devise_scope :user do
get '/login' => 'backdoor#login'
@priyaaank
priyaaank / non_production_routes.rb
Created March 31, 2012 15:42
Splitting Routes for better management
Webapp::Application.routes.draw do
# added for our cukes to run faster,
# in most cases circumventing the whole
# login process
devise_scope :user do
get '/login' => 'backdoor#login'
get '/logout' => 'backdoor#logout'
end
@priyaaank
priyaaank / Gemfile
Created October 21, 2012 08:23
Gemfile for Grape App
source :rubygems
ruby "1.9.3"
gem 'rails', '~> 3.2.0'
gem 'mongoid', "~> 3.0.5"
gem 'bson_ext'
gem 'grape'
@priyaaank
priyaaank / contact_info.rb
Created October 21, 2012 08:39
Models for Modular API with Grape and Rails
class ContactInfo
include Mongoid::Document
field :address_line, :type => String
field :city, :type => String
field :country, :type => String
field :zipcode, :type => String
field :state, :type => String
embeds_many :phone_numbers
@priyaaank
priyaaank / api.rb
Created October 21, 2012 09:32
Modular APIs with Grape and Rails
class API < Grape::API
format :json
error_format :json
version 'v1', :using => :header, :vendor => "App"
rescue_from Mongoid::Errors::DocumentNotFound do |error|
rack_response({"error" => {"message" => "We didn't find what we were looking for"}}.to_json, 404)
end
@priyaaank
priyaaank / Vagrantfile
Created October 25, 2012 17:53
Vagrant configuration
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ci"
# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
@priyaaank
priyaaank / Cheffile
Created October 25, 2012 18:05
Cheffile for Librarian-chef
#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook 'apt'
cookbook 'apache2'
cookbook 'jenkins'