Skip to content

Instantly share code, notes, and snippets.

View MyExperiments's full-sized avatar

Sufinsha Musthafa MyExperiments

  • Trivandrum, Kerala
View GitHub Profile
@MyExperiments
MyExperiments / unicorn
Created January 13, 2016 04:16
Unicorn init.d script
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: unicorn initscript
# Description: unicorn
### END INIT INFO
@MyExperiments
MyExperiments / tar.txt
Created July 23, 2015 06:46
Tar and restore tar files in linux
Tar
===
tar -cvf output.tar file1 file2 folder1/
Restore Tar
===========
tar -xvf output.tar
options
--------
@MyExperiments
MyExperiments / backup.txt
Last active August 29, 2015 14:25
Postgres - Backup and Restore Database
Create dump
------------
pg_dump database_name > pgdumpfile.sql
Create dump and compress
------------------------
pg_dump database_name | gzip -c > pgdumpfile.sql.gz
@MyExperiments
MyExperiments / postgres_installation.txt
Last active August 29, 2015 14:24
PostgreSQL Installation Instructions - Linux
Installation
============
Install PostgreSQL:
-------------------
- sudo apt-get install postgresql
Install GUI Administration application:
---------------------------------------
- sudo apt-get install pgadmin3
Install PHP based Web Administration site (like phpMyAdmin for MySQL database):
@MyExperiments
MyExperiments / application.rb
Last active August 29, 2015 14:02
Adding class/module to lib folder of rails application. By adding the lib folder to autoload_path, you don't need to require the file (require 'file') in other classes.
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module TestApplication
class Application < Rails::Application
#add the lib folder to autoload path
config.autoload_paths += %W(#{config.root}/lib/assets/ #{config.root}/lib/)
class DynamicAttrAccessor
def initialize(hash)
hash.each do |k,v|
if v.is_a?(Hash)
set_attr_accessor(k.to_s, self.class.new(v))
else
set_attr_accessor(k.to_s, v)
end
end
end
@MyExperiments
MyExperiments / deep_open_struct.rb
Last active August 29, 2015 13:56
Convert a nested hash into an OpenStruct object.
require 'ostruct'
def deep_ostruct(hash)
if hash
hash.each do |k,v|
hash["#{k}"] = deep_ostruct(v) if v.is_a?(Hash)
end
end
OpenStruct.new(hash)
end