Skip to content

Instantly share code, notes, and snippets.

@vgvinay2
vgvinay2 / deploy.rb
Created April 10, 2016 18:12 — forked from markoa/deploy.rb
Ingredients to monitor Resque with God automatically via Capistrano (on Ubuntu)
namespace :deploy do
desc "Hot-reload God configuration for the Resque worker"
task :reload_god_config do
sudo "god stop resque"
sudo "god load #{File.join(deploy_to, 'current', 'config', 'resque-' + rails_env + '.god')}"
sudo "god start resque"
end
end
# append to the bottom:
@vgvinay2
vgvinay2 / Create Helper in Rails
Created February 19, 2016 18:03
Create Own helper methods
class ActionView::Helpers::FormBuilder #:nodoc:
def autocomplete_field(method, source, options = {})
@template.autocomplete_field(@object_name, method, source, objectify_options(options))
end
end
@vgvinay2
vgvinay2 / gist:36ab54d95472ef0b057b
Created January 29, 2016 17:40 — forked from bkimble/gist:1365005
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@vgvinay2
vgvinay2 / SQL-Movie-Rating.sql
Created January 27, 2016 11:10
My answers to SQL exercises for db-class.org /Part 1/
/* Delete the tables if they already exist */
drop table if exists Movie;
drop table if exists Reviewer;
drop table if exists Rating;
/* Create the schema for our tables */
create table Movie(mID int, title text, year int, director text);
create table Reviewer(rID int, name text);
create table Rating(rID int, mID int, stars int, ratingDate date);
@vgvinay2
vgvinay2 / facebook.coffee
Created October 9, 2015 15:15 — forked from mupkoo/facebook.coffee
Facebook Like snippet for Turbolinks
class @Facebook
rootElement = null
eventsBound = false
@load: ->
unless $('#fb-root').size() > 0
initialRoot = $('<div>').attr('id', 'fb-root')
$('body').prepend initialRoot
@vgvinay2
vgvinay2 / bash_aliases File in home Directory
Last active October 6, 2015 08:18
This is about Unix N Shell Command
vi ~/.bash_aliases
python
>>> 2.7.0
alias python=python3
>>> 3.4.3
//Constructor
var Person = function (name, age){
//private properties
var priv = {};
//Public properties
this.name = name;
this.age = age;
//Public methods

Ruby language

General

[extend ]

The extend method works similar to include, but unlike include, you can use it to extend any object by including methods and constants from a module. It can add class level methods - something that include can't do.

module Foo
#!/usr/bin/env ruby
require 'pdf/reader' # gem install pdf-reader
# credits to :
# https://github.com/yob/pdf-reader/blob/master/examples/text.rb
# usage example:
# ruby pdf2txt.rb /path-to-file/file1.pdf [/path-to-file/file2.pdf..]
ARGV.each do |filename|
PDF::Reader.open(filename) do |reader|
#!/usr/bin/env ruby
require 'pdf/reader' # gem install pdf-reader
# credits to :
# https://github.com/yob/pdf-reader/blob/master/examples/text.rb
# usage example:
# ruby pdf2txt.rb /path-to-file/file1.pdf [/path-to-file/file2.pdf..]
ARGV.each do |filename|
PDF::Reader.open(filename) do |reader|