Skip to content

Instantly share code, notes, and snippets.

View jay3126's full-sized avatar

Janmejay Rai (Jay) jay3126

View GitHub Profile
@jay3126
jay3126 / Study: Multi-File Bash Scripting and Paths.md
Created May 29, 2016 10:26 — forked from Jeff-Russ/Study: Multi-File Bash Scripting and Paths.md
Study: including other bash scripts from relative paths and absolute paths

Bash Scripting:

Managing Pathnames in Multi-file Bash Projects

Paths can get somewhat muddled up when you execute a Bash script with dependencies. Each script, when executed, is executed at a certain location as demonstrated by echoing pwd from the script. This is the directory assumed if ever you try to source (aka .) from that script.

This location is subject to change as it traces back to the ORIGINAL caller. By "ORIGINAL" I don't mean the location script that called it, or even the location of the script that called the script that called it, I mean the working directory of the first to initiate the chain of calls, which might be the user in the terminal or the location of the clicked executable.

Thing to consider:

  1. The caller's location
@jay3126
jay3126 / secret_key_base
Created March 12, 2016 08:23 — forked from pablosalgadom/secret_key_base
app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)
So i was using Rails 4.1 with Unicorn v4.8.2 and when i tried to deploy my app it doesn't start properly and into the unicorn.log file i found this error message:
"app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)"
After a little research i found that Rails 4.1 change the way to manage the secret_key, so if we read the secrets.yml file located at exampleRailsProject/config/secrets.yml (you need to replace "exampleRailsProject" for your project name) you will find something like this:
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@jay3126
jay3126 / rpg.rb
Created February 29, 2016 18:56 — forked from theHamdiz/rpg.rb
Random Password Generator Ruby Module
module RandomPassword
def generate
# create a one big array of seeding data
seed = [('a'..'z'), ('!'..'+'), (1..9), ('A'..'Z')].map { |e| e.to_a }.flatten
# get random 16 characters from this array
original = (0..16).map { seed[rand(seed.length)] }.join
# just to be sure, randomize them once more
original.split('').shuffle.join
end
end
@jay3126
jay3126 / .bashrc
Created January 5, 2016 10:18 — forked from vsouza/.bashrc
Golang 1.5 setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell or bash.
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@jay3126
jay3126 / postgres-cheatsheet.md
Last active August 29, 2015 14:26 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

Magic words:

psql -U postgres

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

  • \q: Quit/Exit
  • \c __database__: Connect to a database
  • \d __table__: Show table definition including triggers
require "rubygems"
require "octokit" # gem install octokit
1.upto(5) do |page|
Octokit.repositories("railscasts", page: page, per_page: 100).each do |repo|
system "git clone git://github.com/railscasts/#{repo.name}"
end
end
require 'rss'
require 'open-uri'
p "Downloading rss index"
# If you are a Railscasts Pro subscriber, you will have a different RSS feed with Pro casts
# If this is the case, go to http://railscasts.com/, find it and sub it below
rss_string = open('http://feeds.feedburner.com/railscasts').read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse
#!/usr/bin/ruby
require 'rss'
p 'Downloading rss index'
rss_string = open('http://feeds.feedburner.com/railscasts').read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse
videos_filenames = videos_urls.map {|url| url.split('/').last }
#!/usr/local/bin/ruby
# A script to download the latest episodes from railscasts.com
#
# author: modsaid <mahmoud@modsaid.com>
# mechanize support: Hossam Hammady <github@hammady.net>
# gem install mechanize
require 'rubygems'
require 'mechanize'