Skip to content

Instantly share code, notes, and snippets.

@pointcom
pointcom / pp.rb
Created January 2, 2018 13:31
Ruby 2.5
require 'pp'
@pointcom
pointcom / slice.rb
Last active January 2, 2018 13:30
Ruby 2.5
{foo: "bar", baz: "qux", quux: "corge", grault: "garply"}.slice(:foo, :grault)
=> {:foo=>"bar", :grault=>"garply"}
# Before
irb(main):001:0> class Auth; end
=> nil
irb(main):002:0> class Twitter; end
=> nil
irb(main):003:0> Twitter::Auth
(irb):4: warning: toplevel constant Auth referenced by Twitter::Auth
# After
irb(main):001:0> class Auth; end
2.tap {|x| x*2 }
=> 2
2.yield_self {|x| x*2 }
=> 4
# Before you had to use begin
lambda do
begin
raise 'err'
rescue
$! # => #<RuntimeError: err>
end
end.call
# Now you can simply use rescue
@pointcom
pointcom / struct.rb
Last active January 2, 2018 13:46
Ruby 2.5
Customer = Struct.new(:name, :address, keyword_init: true)
Customer.new(name: "Dave", address: "123 Main")
#=> #<struct Customer name="Dave", address="123 Main">
@pointcom
pointcom / docker-tag-list.sh
Created November 26, 2017 21:19
List all the tags of a particular docker image
#!/bin/bash
i=0
while [ $? == 0 ]
do
i=$((i+1))
curl https://registry.hub.docker.com/v2/repositories/library/ruby/tags/?page=$i 2>/dev/null|jq '."results"[]["name"]'
done
@pointcom
pointcom / Dockerfile
Created October 7, 2017 16:17
Phoenix project dockerized
FROM elixir:1.5.0
WORKDIR /app
# Install Hex
RUN mix local.hex --force
# Install rebar3
# Needed to compile dependency :ranch
RUN mix local.rebar --force
@pointcom
pointcom / docker_install.sh
Last active August 29, 2015 14:22
OSX Docker Machine + Docker Compose + Docker Client + Use NFS instead of vboxsf for /Users dir
#!/bin/sh
# This Script aims to setup a docker environment for Linux or OSX with docker client, docker-machine and docker-compose
# All binaries are install in /usr/local/bin/ directory.
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
os=$(uname -s)
arch=$(uname -m)
var hash = document.location.hash.replace('#', '');
$('a[data-target='+hash+']').trigger('click');