Skip to content

Instantly share code, notes, and snippets.

@rkjha
rkjha / database_config_pg_openshift.yml
Created March 21, 2014 17:05
Production config for database.yml while deploying a Rails application to openshift. [using postgresql]
production:
adapter: postgresql
encoding: unicode
pool: 5
database: <%=ENV['OPENSHIFT_APP_NAME']%>
host: <%=ENV['$OPENSHIFT_POSTGRESQL_DB_HOST']%>
port: <%=ENV['$OPENSHIFT_POSTGRESQL_DB_PORT']%>
username: <%=ENV['OPENSHIFT_POSTGRESQL_DB_USERNAME']%>
password: <%=ENV['OPENSHIFT_POSTGRESQL_DB_PASSWORD']%>
@rkjha
rkjha / wordpress_nginx_config.conf
Last active March 17, 2023 10:23
a sample wordpress config for nginx
server {
listen 80;
root /home/username/example.com;
index index.php index.html;
server_name example.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
@rkjha
rkjha / book.rb
Last active December 20, 2015 10:38
Library, Shelf and Book Model using Ruby/Active Record (in a typical ruby/rack application)
class Book < ActiveRecord::Base
attr_accessible :title, :author, :lang, :genre, :shelf_id
belongs_to :shelves
def enshelf shelf_id
@book.shelf_id = shelf_id
end
def unshelf
# setting shelf_id to nil means book is not on the shelf
@rkjha
rkjha / silly_methods.rb
Created July 30, 2013 18:41
silly_methods
# silly_sum
def silly_sum numbers
sum = 0
numbers.each_with_index {|number, index|
sum = sum + number*index
}
puts "sum = #{sum}"
end
puts "### silly_sum ###"
@rkjha
rkjha / frequency_db.rb
Last active December 18, 2015 00:09
First ruby program reads a file containing numbers (separated by space), and calculates the each occurrence of the number (a.k.a frequency distribution). Second one, simply prints a number from 1 to n with the condition (if it's divisible by 3 then Hip, divisible by 5, then Hop, and if it's divisible by both 3 and 5, then it prints Whazaa)
# assuming the file is there in the same dir as numbers.txt
file = File.open("numbers.txt", 'r')
frequency_db = Hash.new
file.each_line do |line|
line_n = line.split
line_n.each do |n|
if frequency_db.has_key?(n)
frequency_db[n]+=1
@rkjha
rkjha / example.com
Created April 11, 2013 15:31
Apache VirtualHost Configuration
<VirtualHost *:80>
ServerAdmin name@example.com
ServerName example.com
DocumentRoot /home/user_name/example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / http://example.com/
</VirtualHost>
@rkjha
rkjha / database.yml
Last active December 10, 2015 17:38
database.yml
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
@rkjha
rkjha / deploy.rb
Last active December 10, 2015 17:29
Capistrano deploy.rb
require "bundler/capistrano"
#require "delayed/recipes"
server "YOUR_IP_ADDRESS", :web, :app, :db, primary: true
set :rails_env, "production" #added for delayed job
set :application, "YOUR_APP_NAME"
set :user, "mrhuman"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
@rkjha
rkjha / unicorn_init.sh
Created January 6, 2013 16:21
unicorn_init.sh
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/mrhuman/apps/YOUR_APP_NAME/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=mrhuman
set -u
@rkjha
rkjha / Capfile
Created January 6, 2013 16:19
Capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks