Skip to content

Instantly share code, notes, and snippets.

View codemilan's full-sized avatar
🪄
composing...

Milan Rawal codemilan

🪄
composing...
View GitHub Profile
@codemilan
codemilan / gist:ddc81229f4dfc765da5698a61c4c6af9
Created May 12, 2018 16:08 — forked from ssjr/gist:5970762
My setup for Ruby on Rails with Mac OS X

My initial setup for Ruby on Rails development

Note: I'm using Mac OS X Lion (10.7.5)

All links, commands and order to install

  1. Download Xcode
  2. Open Xcode, Xcode (menu) > Preferences... > Downloads. Install Command Line Tools
  3. Install Homebrew
  • ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'memory_profiler'
gem 'benchmark-ips'
end
@codemilan
codemilan / ar_arel_wrapper.rb
Created June 14, 2018 11:13 — forked from tokland/ar_arel_wrapper.rb
Simple wrapper over arel
require 'active_record'
require 'arel'
# Ruby-like syntax in AR conditions using the underlying Arel layer (Rails >= 3.0).
#
# What you would usually write like this:
#
# User.where(["users.created_at > ? AND users.name LIKE ?", Date.yesterday, "Mary"])
#
# can now be written like this (note those parentheses required by the operators precedences):
@codemilan
codemilan / RunAProxyOnAmazonEC2VPC.md
Created June 26, 2018 09:11 — forked from webinista/RunAProxyOnAmazonEC2VPC.md
Create a proxy server on an Amazon EC2 (VPC) instance

This will create a proxy server in whatever your availability zone your VPC is in. For me, that's us-east-1b. For you, that may be something different. Steps 10+ should more or less work regardless of your provider since those steps cover the setup and configuration of TinyProxy.

  1. Click the Launch Instance button.
  2. Choose Ubuntu Server 14.04 LTS (HVM), SSD Volume Type. This isn't strictly necessary. If you choose another OS, check its documentation for how to install new packages.
  3. On the Choose an Instance Type screen, select t2.micro. It's Free Tier eligible.
  4. Click the Next: ... buttons until you reach the Configure Security Group screen.
    • You may wish to reduce the amount of storage on the Add Storage screen. This is optional.
    • You may wish to add a tag on the Tag Instance screen. This is also optional.
  5. On the Configure Security Group screen:
  • Select Create a new security group.
@codemilan
codemilan / hmac_api_request.rb
Created July 11, 2018 09:49
Signature is a HMAC-SHA256 encoded message
# NOTES::Important (!) To construct a signature string, parameters should be ordered alphabetically by
# initials of parameter names. Otherwise the e-signature verification process will fail.
# Post request.
require "net/http"
require "uri"
require 'openssl'
require "base64"
require "rubygems"
require "json"
@codemilan
codemilan / fish_shell.md
Created August 7, 2018 04:42 — forked from idleberg/fish_shell.md
Instructions on how to install Fish shell on Mac OS X, including Oh My Fish!. Also includes several useful functions.

Installation

  1. Install fish via Brew
  2. Optionally install Oh My Fish!
  3. Add fish to known shells
  4. Set default shell to fish
brew install fish  
curl -L https://get.oh-my.fish | fish
@codemilan
codemilan / introrx.md
Created August 9, 2018 04:43 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@codemilan
codemilan / c10k.ru
Created November 4, 2018 10:23 — forked from WJWH/c10k.ru
The double hijack trick, serving 65k connections from a single ruby process
# This server demo does a socket hijack in Rack and then saves the socket to a global variable
# to prevent it from being GCed when the Puma thread ends. It will then write "BEEP" to each
# socket every ten seconds to prevent the connection timing out. During testing, it easily
# handled up to 65523 connections, after which it ran into the `ulimit` for open file descriptors.
# The bit with the waiting area is there because a normal `Set` is not thread safe and it would
# drop socket due to race conditions. The `Queue` is thread safe and will make sure all sockets
# are preserved.
# run with `rackup -q -p 8000 -o 0.0.0.0 c10k.ru`
# testing: install `ab` and then run `ab -c 20000 -n 20000 <ip adress of server>:8000/
@codemilan
codemilan / filterable.rb
Last active June 27, 2019 04:34 — forked from justinweiss/filterable.rb
Filterable
# https://www.justinweiss.com/articles/search-and-filter-rails-models-without-bloating-your-controller/
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
@codemilan
codemilan / ssl_config.rb
Last active December 2, 2019 09:15
Running puma in ssl mode in development environment.
# Ref:- 'https://gist.github.com/tadast/9932075'
# Inside your rails app root directory.
# run "mkdir config/certs && touch config/certs/.keep"
# Add below two lines in .gitignore
# /config/certs/*
# !/config/certs/.keep
# Add below code in config/puma.rb
if Rails.env.development?