Skip to content

Instantly share code, notes, and snippets.

View harshalbhakta's full-sized avatar

Harshal Bhakta harshalbhakta

View GitHub Profile
@harshalbhakta
harshalbhakta / rails_comments_sample.rb
Last active December 13, 2015 20:09
Rails class commenting empty template.
##
# Class description
# goes here.
class State < ActiveRecord::Base
#-- attributes
attr_accessor :id, :name, :slug, :country_id
#-- validations
@harshalbhakta
harshalbhakta / all_packages.sh
Last active December 15, 2015 09:48
Setup Ubuntu + Git + Rails + Vim + Postgresql
# copy command to clipboard
$ sudo apt-get install xclip

Generate new rails app project

Create a new app specifying the rails version & database.

$ rails _3.2.11_ new learnapt-web --database postgresql --skip-test-unit
public void loadUpdates(boolean loadWordADay)
{
try
{
if (Util.isNetworkAvailable(this))
{
sendProgress(ProgressMode.UPDATE_STARTED.ordinal());
//-- Update Word of the day
if(loadWordADay) {
@harshalbhakta
harshalbhakta / angular_factory_resource.js.coffee
Created September 16, 2013 07:13
Angular resource with additional methods.
app.factory "User", ["$http","$resource",($http,$resource) ->
User = $resource("/roles/:id", {id: "@id"}, {update: {method: "PUT"}})
# Initialize the data using a static method
User.init = (data) ->
angular.extend this, data
# a static method to retrieve User by ID
User.get_it = (id) ->
# Authenticate:
curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-X POST http://localhost:3000/users/sign_in \
-d "{'user' : { 'email' : 'test@example.com', 'password' : 'password'}}" \
-c cookie
# Show:
curl http://localhost:3000/api/v1/Action -H 'Authorization: Token token="api_key_goes_here"'
@harshalbhakta
harshalbhakta / rails_installation_RDoc_Warning
Created November 7, 2013 05:56
RDoc warning while installing Rails.
$ gem install rails
Fetching: i18n-0.6.5.gem (100%)
Successfully installed i18n-0.6.5
Fetching: multi_json-1.7.9.gem (100%)
Successfully installed multi_json-1.7.9
Fetching: tzinfo-0.3.37.gem (100%)
Successfully installed tzinfo-0.3.37
Fetching: atomic-1.1.13.gem (100%)
Building native extensions. This could take a while...
Successfully installed atomic-1.1.13

Here's how to install PostgreSQL and have it run automatically at startup, on an Ubuntu 10.04 virtual machine using Vagrant. This took me a while to figure out:

Add the default lucid32 base box to your vagrant, if you haven't already:

host> vagrant box add lucid32 http://files.vagrantup.com/lucid32.box 

Now make a new lucid32 virtual machine and install postgresql on it:

@harshalbhakta
harshalbhakta / gist:178563e42c127b28f374
Created June 18, 2014 13:23
Delete open Postgresql connections
-- http://stackoverflow.com/a/5408501
-- PostgreSQL 9.1 and below:
SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND procpid <> pg_backend_pid();
-- PostgreSQL 9.2 and above: