Skip to content

Instantly share code, notes, and snippets.

View rake-sh's full-sized avatar

Rakesh Haridas rake-sh

View GitHub Profile
@rake-sh
rake-sh / integer.rb
Created December 25, 2019 11:26 — forked from pithyless/integer.rb
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
@rake-sh
rake-sh / gist:37c6c9280018a9c488dbc42c30dca7ac
Created January 10, 2019 01:11 — forked from TwP/gist:981176
A simple rack middleware that allows you to post JSON body data. We are using the YAJL json library for ruby. Feel free to substitute your own.
require 'yajl'
module Rack
# A Rack middleware for parsing POST/PUT body data when Content-Type is
# <tt>application/json</tt>.
#
class JsonPostBody
@rake-sh
rake-sh / custom_log_subscriber.rb
Created January 7, 2019 05:43 — forked from nbogie/custom_log_subscriber.rb
attempt to change out ActionController::LogSubscriber in rails 3
#put this in config/initializers/custom_ac_log_subscriber.rb
## needed if we re-enable additions
#
#require 'active_support/core_ext/object/blank'
module MyApp
#TODO: we should no longer interit from ActionController::LogSubscriber
# as we are not truly unregistering the parent.
class CustomAcLogSubscriber < ActiveSupport::LogSubscriber
INTERNAL_PARAMS = ActionController::LogSubscriber::INTERNAL_PARAMS
@rake-sh
rake-sh / SOLID.markdown
Created July 4, 2018 03:31 — forked from emaraschio/SOLID.markdown
SOLID Principles with ruby examples

#SOLID Principles with ruby examples

##SRP - Single responsibility principle A class should have only a single responsibility.

Every class should have a single responsibility, and that responsibility should be entirely encapsulated. All its services should be narrowly aligned with that responsibility, this embrace the high cohesion.

##OCP - Open/closed principle Software entities should be open for extension, but closed for modification.

@rake-sh
rake-sh / PhantomJS Install.md
Created May 24, 2018 12:57 — forked from pboling/PhantomJS Install.md
How to install old PhantomJS 1.8.2 on Mac OS X
@rake-sh
rake-sh / aliases.sh
Created April 28, 2018 12:57 — forked from subelsky/aliases.sh
Useful aliases for Ruby and Rails development and git maintenance
alias a='ack'
alias a?='alias | grep -i'
alias adx='rake db:drop && rake db:create && heroku pg:transfer --from black --to postgres://postgres@localhost/staq_development --confirm staqweb --app staqweb && rails r "User.all.each { |u| u.update_attribute(:password,%q(password)) }" && rake db:test:prepare'
alias b='bundle'
alias bb='bundle install --binstubs=.bundle/bin --path=.bundle/gems && bundle package --all && reload ; sd'
alias bc='bin/console'
alias be='bundle exec'
alias bea='bundle exec annotate'
alias bu='bundle update'
alias bus='bundle update staq_extraction'

#Setting up Nginx on Your Local System ###by Keith Rosenberg

##Step 1 - Homebrew The first thing to do, if you're on a Mac, is to install homebrew from http://mxcl.github.io/homebrew/

The command to type into terminal to install homebrew is:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
@rake-sh
rake-sh / benchmark_meanshop_heroku.txt
Created August 9, 2017 19:48 — forked from amejiarosario/benchmark_meanshop_heroku.txt
Benchmark of meanshop app deployed at Heroku
$ ab -c 100 -n 10000 https://meanshop-8.herokuapp.com/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking meanshop-8.herokuapp.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests

Host to Host a Rails App on a Home Server

Hosting services like Heroku and Amazon EC2 are nice. That is, until they cost money. Some things are worth running on your own hardware, especially when the cost and Terms of Service requirements outweigh the expense of rolling your own hosting.

I am writing this because I recently had to figure all this out in order to host a personal blog off a Raspberry Pi, and I thought I'd share what I learned. This guide assumes that you already know how to install Ruby and you know how to use Rails. If you don't, look those up first before coming back to this guide.

Prerequisites

  • Ruby >=2.0
  • Rails >=4.0
  • Nginx
@rake-sh
rake-sh / beanstalk_nginx.conf
Created May 11, 2017 14:15 — forked from petelacey/beanstalk_nginx.conf
Nginx always-on SSL config for ElasticBeanstalk
files:
"/etc/nginx/conf.d/000_APP_NAME.conf":
mode: "000755"
owner: root
group: root
content: |
upstream APP_NAME_app {
server unix:///var/run/puma/my_app.sock;
}