Skip to content

Instantly share code, notes, and snippets.

Working on something magical

Shyam Habarakada shyam-habarakada

Working on something magical
  • Smartsheet, 10Kft
  • Seattle, WA
  • Twitter @shyamh
View GitHub Profile
shyam-habarakada / docker-statamic-v2
Last active Aug 11, 2019
A docker file for running statamic 2. Adds on GD and Exif dependencies on top of php:7.0-apache
View docker-statamic-v2
FROM php:7.0-apache
RUN apt-get update \
&& apt-get install -y curl vim \
&& a2enmod rewrite
# Statamic requires GD and Exif
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
View test-url.html
<!DOCTYPE html>
<script src="url.js"></script>
var url = new URL('');
for (var key in url) {
console.log(key, url[key]);
# add this to your ~/.bash_profile to get a bash prompt like
# ~/your-path (git-branch-name) /dockerMachineName/ $
function color_my_prompt {
local __user_and_host="\[\033[01;32m\]\u@\h"
local __cur_location="\[\033[01;34m\]\w"
local __git_branch_color="\[\033[31m\]"
local __git_branch='`command git branch 2> /dev/null | /usr/bin/grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __docker_machine_name_color="\[\033[36m\]"
local __docker_machine_name='`if [ $DOCKER_MACHINE_NAME ]; then echo "/$DOCKER_MACHINE_NAME/ "; fi`'
View application_controller.rb
class ApplicationController < ActionController::Base
#In rails 3.0.1+ it is no longer possible to do this anymore;
# rescue_from ActionController::RoutingError, :with => :render_not_found
#The ActionController::RoutingError thrown is not caught by rescue_from.
#The alternative is to to set a catch-all route to catch all unmatched routes and send them to a method which renders an error
#As in
shyam-habarakada / .profile
Created May 19, 2016 — forked from airtonix/.profile
dynamic npm .bin.
View .profile
# Copy this into your `~/.profile`.
# This setup an incredibly ugly hack that recompiles your `PATH`
# everytime the prompt is printed.
# I need this to inject the nearest `node_modules/.bin` into my
# path to make it easy to use the binarys there.
# Your normal PATH exports here
export PATH=$HOME/bin:$PATH
View insert_sql.rb
record = => 'Yay', :body => 'This is some insert SQL')
# easiest way to achieve this is by calling protected #arel_attributes_values (tested in
# rails 3.2.13). the alternative is to build the entire insert statement using arel >_>
record.class.arel_table.create_insert \
.tap { |im| im.insert(record.send(:arel_attributes_values, false)) } \
View gist:53ba7e63730072e0d9ce

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

View gist:009b67826e16153373d5
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
shyam-habarakada / rails-assert.rb
Created Jul 3, 2014
A simple rails assert method
View rails-assert.rb
def assert(message = 'assertion failed')
unless block_given? and yield
if Rails.env.development? or Rails.env.test?
raise message
Rails.logger.warn "(assert) #{message}"
View deploy.rb
# Requires the presence of a failover node that will get activated when the site is in maintenance mode, and will be disabled when the site is live.
namespace :deploy do
namespace :web do
desc <<-DESC
Disable via Cloud Load Balancers
task :lbdisable do