Skip to content

Instantly share code, notes, and snippets.

View vparihar01's full-sized avatar

Vivek Parihar vparihar01

View GitHub Profile
@vparihar01
vparihar01 / database.yml.example.mysql2
Created March 26, 2013 09:35
Rails 3 database.yml examples
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@vparihar01
vparihar01 / memstats.rb
Created March 28, 2013 17:56
Small piece of of code to check the memory stats for ruby on rails application, for any particular method.
require 'csv'
def memstats
size = `ps -o size= #{$$}`.strip.to_i
end
memstats
test = CSV.read('test.csv', headers: true)
test.count{|v| v['any_column'] = ~/any_text_in_that_column_to_search/}
memstats

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS
public String demoMethod(List<NameValuePair> params) {
String args = params.get(1).toString();
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary =  "goBonziteam";
/*int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
File temp_file = new File("foo.txt");*/
HttpsURLConnection conn;
require "net/http"
require "uri"
require 'json'
# Token used to terminate the file in the post body. Make sure it is not
# present in the file you're uploading.
BOUNDARY = "goBonziteam"
JSON_RESPONSE = ActiveSupport::JSON.decode('{
"args": {
"values": {
@vparihar01
vparihar01 / csv_creating.rb
Created April 10, 2013 11:22
the snippet which creates a csv for the given object, we could aslo use streaming to do this same to save memory consumption.
csv_string = FasterCSV.generate do |csv|
csv << ["Idea Name","Total Votes count","Date Created","Created By"]
csv << [@idea.title, @idea.votes.size,@idea.created_at.strftime("%B %d, %Y"),@idea.created_by]
csv << ["Months","Total Votes count"]
votes_count.each_with_index do |i,j|
csv << [month_names[j] , votes_count[j] ]
end
@vparihar01
vparihar01 / reading_csv_data.rb
Created April 10, 2013 12:53
Simple gist to read data from csv and populating data to database.
require "csv"
require "fileutilities"
csv_data = File.Read("#{Rails.public_path}/location_of_csv_inside_your_public_dir.csv")
csv = CSV.parse(csv_data,:headers => false)
csv.each do |row|
puts row.inspect
age = AgeGroup.find_by_name(row[2])
category = CategoryFlag.find_by_name(row[4]) if row[5] == "flag"
category = CategoryTackle.find_by_name(row[4]) if row[5] == "tackle"
Drill.create(:name => row[0], :age_group_id =>age.id,:category_id=>category.id,:game_type=>row[5],:file=>row[6])
@vparihar01
vparihar01 / registrations_controller.rb
Created April 16, 2013 09:19
devise api for registration and login.
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@vparihar01
vparihar01 / sanitize_params.rb
Created April 26, 2013 05:38
Controllers should sanitize params before performing any other logic.
class ExampleController < ActionController::Base
def create
Example.create(sanitized_params)
end
def update
Example.find(params[:id]).update_attributes!(sanitized_params)
end
protected