Skip to content

Instantly share code, notes, and snippets.

View tiagopog's full-sized avatar

Tiago Guedes tiagopog

View GitHub Profile
@tiagopog
tiagopog / async_test.ex
Last active November 14, 2016 06:38
Elixir - Kernel.spawn/1 & Async
defmodule AsyncTest do
@contents ["foo", "bar", "foobar"]
@output "async_test"
def run do
File.rm_rf!(@output)
File.mkdir_p!(@output)
@contents
|> Enum.with_index
|> Enum.map(&write_content_async(&1))
@tiagopog
tiagopog / user.ex
Created November 13, 2016 05:03
Elixir - Sample of struct + API
defmodule User do
defstruct name: nil, gender: nil, roles: [:normal]
defmodule NameError do
defexception message: "Name is too short"
end
def add_name(%User{} = user, name) when is_binary(name) do
try do
validate!(name: name)
@tiagopog
tiagopog / argv_example.rb
Last active May 19, 2016 20:03
ARGV Example
ARGV << '--help' if ARGV.empty?
aliases = {
"g" => "generate",
"d" => "destroy",
"c" => "console",
"s" => "server",
"db" => "dbconsole",
"r" => "runner"
}
@tiagopog
tiagopog / class_eval.rb
Last active June 23, 2016 15:29
Ruby - Utils
require 'irb'
class Foobar
def foo
:foo
end
end
Foobar.class_eval do
def bar
@tiagopog
tiagopog / Dockerfile
Last active August 11, 2018 10:38
Docker + Docker Compose example
FROM ruby:2.2.3
MAINTAINER [email protected]
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs
require 'forwardable'
class CustomEnumerable
extend Forwardable
include Enumerable
def_delegators :@collection, :each, :map
# The above is the same of doing this:
#
@tiagopog
tiagopog / demo.ex
Last active October 27, 2016 18:33
Elixir - Code Samples
defmodule Demo do
def greet(name) do
IO.puts "Hello #{name} from Elixir"
end
def api_call do
{:ok, "foo"}
end
end
@tiagopog
tiagopog / define_method_example.rb
Created March 14, 2016 16:12
Ruby's define_method
class A
def fred
puts "In Fred"
end
def create_method(name, &block)
self.class.send(:define_method, name, &block)
end
define_method(:wilma) { puts "Charge it!" }
end
class B < A
function add(x) {
return function(y) { return x + y; };
}
var addTo10 = add(10);
console.log(addTo10(5)); // 15
console.log(addTo10(10)); // 20
NODE_ENV=production
APP_ACCESS_TOKEN=ed63f03d697993421e39848e66ede6d232c07cad
APP_SECRET=df5728ee-eb4b-47c0-831e-1f375eb51155
APP_TOKEN_SEPARATOR=:
DOMAIN=localhost
PORT=5000
############################