Skip to content

Instantly share code, notes, and snippets.

# Run external command and abort on failure
def shell(*cmd)
return if cmd.empty?
prog = cmd.first.to_s.split.first
abort "#{prog}: command not found" if `which #{prog}`.empty?
system *cmd
abort "#{prog}: interrupted, signal #{$?.termsig}" if $?.signaled?
abort "#{prog}: execution failed, exit code #{$?.exitstatus}" unless $?.success?
end
### USAGE
###
### ./ElasticSearch.sh 1.5.0 will install Elasticsearch 1.5.0
### ./ElasticSearch.sh 1.4.4 will install Elasticsearch 1.4.4
### ./ElasticSearch.sh will fail because no version was specified (exit code 1)
###
### CLI options Contributed by @janpieper
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch
### ElasticSearch version
@StasKoval
StasKoval / install-comodo-ssl-cert-for-nginx.rst
Last active September 1, 2015 13:44 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@StasKoval
StasKoval / regex-console.text
Last active September 14, 2015 13:10
Remove all console.log from JS in Sublime
Ensure regex button is selected and then type this in the search field.
\s*console\.log(.*);
@StasKoval
StasKoval / application.rb
Created September 27, 2015 00:21 — forked from stereoscott/application.rb
Redirect Mobile User-Agent to Subdomain as Rack Middleware (in Rails)
module YourApp
class Application < Rails::Application
# ...
config.middleware.insert_before "Rack::Cache", "SubdomainRedirect"
# ...
end
end
@StasKoval
StasKoval / gist:d2afb91aace974a2030b
Created December 2, 2015 13:09 — forked from alex-zige/gist:5795358
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@StasKoval
StasKoval / obervable_example.rb
Created December 30, 2015 18:18 — forked from jensendarren/obervable_example.rb
Example of using Observable in Ruby
require 'observer'
class CoffeeShop
include Observable
attr_reader :customers
def initialize(name, capacity)
@name = name
@capacity = capacity
@customers = []
@StasKoval
StasKoval / enumerable_example.rb
Created December 30, 2015 18:19 — forked from jensendarren/enumerable_example.rb
See rotati blog post
class Coffee
attr_accessor :name
attr_accessor :strength
def initialize(name, strength)
@name = name
@strength = strength
end
def <=>(other_coffee)
class ReportsController < ApplicationController
def group_columns columns, items
numitems = items.length
rows = numitems / columns
rows += 1 if numitems % columns > 0
extras = numitems % rows if rows > 0
1.upto(rows).map { |rownum|
# distribute the extras evenly
extra = 0
@StasKoval
StasKoval / common.yml
Created February 2, 2016 18:14 — forked from akurkin/common.yml
ROSI docker-compose.yml
#
# Shared definition of ruby microservice
#
microservice:
command: "runsvdir /etc/service"
environment:
PORT: 3000
RAILS_ENV: development
SERVICE_PLATFORM: "mia"
ports: