Skip to content

Instantly share code, notes, and snippets.

@ej2015
ej2015 / deploy.rb
Created August 22, 2017 00:22
Deploy current branch by default with Capistrano3, but use master for production
#/config/deploy.rb
#use current branch:
# cap my_app:staging deploy
#specify a branch:
# cap my_app:staging deploy BRANCH=not-current-branch
set :current_branch, `git rev-parse --abbrev-ref HEAD`.strip
set :branch, ENV['BRANCH'] || fetch(:current_branch)
@ej2015
ej2015 / gist:590d31c8b5420f4dfe573db7ee24c789
Created October 19, 2017 22:48
pretty print json on OS X
brew install jsonpp
curl -XGET "http:/localhost:9200/user/_mapping/admin" | jsonpp
@ej2015
ej2015 / gist:ee6c8f02777109f7f5988afd903791ca
Created December 14, 2017 01:00
modify rake task with #enhance
#add prerequisites
task :prereq_1 do
#always halt tasks
raise if false
end
#extend task to include prerequisite
Rake::Task['db:setup'].enhance [:prereq_1]
@ej2015
ej2015 / rake_arg.rake
Last active December 14, 2017 01:33
pass arguments to rake task
#pass in arguments as symbol
task :first_task, [:first, :second] do |t, args|
puts args[:first]
puts args[:second]
end
#pass in arguments for dependencies
task :main_task, [:first, :second] => :first_task do |t, args|
puts 'main task'
end
@ej2015
ej2015 / retrieve_s3_file_with_fog.rb
Created March 6, 2018 15:43
Retrieve AWS S3 file with Fog
require 'fog/aws'
con = Fog::Storage.new(
provider: 'AWS',
aws_secret_access_key: ENV["AWS_KEY"],
region: ENV["AWS_REGION"],
aws_access_key_id: ENV["AWS_ID"],
connection_options: { region: EVN["AWS_REGION"] }
)
## Fog::AWS::Storage object
@ej2015
ej2015 / multiple_ssh_setting.txt
Created March 8, 2018 03:13
Use multiple ssh keys
### 1. create your keys
### 2. add keys to .ssh/config
##~/.ssh/config
#user1 account
Host bitbucket-user1
HostName bitbucket.org
User git
IdentityFile ~/.ssh/user1_rsa
IdentitiesOnly yes
require 'json'
require 'csv'
data = File.open("occupation.csv").read
a = CSV.parse(data).to_json
b = JSON.parse a
c = b.to_h
@ej2015
ej2015 / minitest_spec_expectations.md
Created June 22, 2018 22:49 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@ej2015
ej2015 / curl.md
Created July 1, 2018 21:10 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@ej2015
ej2015 / require_file.rb
Last active July 24, 2018 20:58
require files in Ruby
#given files a.rb and b.rb in the same directory
#b.rb
dir = File.expand_path('.',__dir__)
# $: is a short form for $LOAD_PATH
$:.unshift(dir) unless $:.include?(dir)
require 'a'
## now we can run b.rb from anywhere and it will require a.rb successfully.