Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / config.ru
Created March 21, 2014 17:58
Default config.ru in a Rails application.
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
@rkjha
rkjha / rbenv-config-bash.sh
Created March 23, 2014 21:41
adding rbenv to bash
export RBENV_ROOT="${HOME}/.rbenv"
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
fi
@rkjha
rkjha / enable-gzip-nginx.conf
Last active June 22, 2018 06:53
Enable gzip compression in nginx
## Enable gzip ##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 5120;
gzip_proxied any;
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
@rkjha
rkjha / browser-caching-nginx.conf
Last active August 29, 2015 13:57
Cache static content (browser caching) with nginx (add this to /etc/nginx/sites-available/yoursite.conf)
# Cache static content
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Vary Accept-Encoding;
access_log off;
}
@rkjha
rkjha / add-to-functions.php
Last active August 29, 2015 13:58
Add this to theme's `function.php`, in order to load jQuery from google cdn and jquery migrate from jQuery cdn (don't forget to update the plugin version)
/* loads minified jQuery (1.10.2) from Google CDN and jQuery migrate from jQuery CDN */
function jquery_cdn() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_deregister_script('jquery-migrate');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', false, '1.10.2');
wp_register_script('jquery-migrate', 'http://code.jquery.com/jquery-migrate-1.2.1.min.js', false, '1.2.1');
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-migrate');
}
@rkjha
rkjha / bash_shortcut.sh
Last active August 29, 2015 13:58
Enable/disable 2nd monitor in ubuntu [using xrandr]. Add these lines to `~/.bash_alias.sh` (and update device name accordingly) and reload bash config. (`source ~/.bashrc`)
# bash alias for turning on/off 2nd monitor
alias 2m_off='xrandr --output HDMI-0 --off'
alias 2m_on='xrandr --output HDMI-0 --auto --right-of VGA-0'