Skip to content

Instantly share code, notes, and snippets.

View javierg's full-sized avatar

Javier Guerra javierg

View GitHub Profile
defmodule PhoenixUeberauthComeonin.Repo.Migrations.CreateUsers do
use Ecto.Migration
def change do
create table(:users) do
add :name, :string
add :email, :string
add :password, :string
timestamps()
end
end
@javierg
javierg / simple_tcp.ex
Last active October 15, 2015 03:08
Simple TCP server on Elixir
# Shameless copy from http://learnyousomeerlang.com/buckets-of-sockets
defmodule SimpleTcp do
def start_server(port) do
pid = spawn fn ->
{:ok, listen} = :gen_tcp.listen(port, [:binary, {:active, false}])
spawn fn -> acceptor(listen) end
:timer.sleep(:infinity)
end
{:ok, pid}
@javierg
javierg / couch_query.ex
Last active October 24, 2016 11:28
Elixir CouchView from: http://pastebin.com/BEqKKH99#
defmodule CouchQuery do
use GenServer.Behaviour
def start_link() do
:gen_server.start_link(__MODULE__, [], [])
end
def set_timeout(pid, timeout) do
:gen_server.call(pid, {:set_timeout, timeout})
end
@javierg
javierg / all_view.erl
Created December 7, 2013 16:01
This is an Erlang couchdb view for getting all the documents that meet the "namespace/id" criteria, emiting the namespace as document type.
% Document design: {"_id": "namespace/edf42", ...}
fun({Doc}) ->
Id = proplists:get_value(<<"_id">>, Doc, null),
NameSpace = binary:bin_to_list(Id),
case re:split(NameSpace, "[/]") of
[_] -> null;
[Type, BaseId] -> Emit(Type, BaseId)
end
end.
@javierg
javierg / gist:4742784
Created February 8, 2013 23:21
Fortune Teller Machine
class FortuneTellerMachine
WELCOME = "Hola ¿Quiéres saber tu fortuna?"
REQUEST = "Fortuna por monedas, yo quiero yo quiero monedas (2): "
CHANGE_BACK = "Here is your change"
COST = 2
def initialize
clear
end
@javierg
javierg / gist:4741870
Last active December 12, 2015 08:08
Fortuna por moneda stateless
class FortuneTellerMachine
def initialize
@coins = 0
end
def start
puts "Hola ¿Quiéres saber tu fortuna?"
@coins += 1
if @coins == 1
puts "necesito otra moneda, yo quiero moneda."
@javierg
javierg / gist:4708386
Created February 4, 2013 18:06
my.cnf.tmpl
[mysqld_safe]
socket = /tmp/mysql.sock
[server]
character_set_server=utf8
collation_server=utf8_unicode_ci
skip_character_set_client_handshake
default_table_type=innodb
transaction-isolation=READ-COMMITTED
@javierg
javierg / current-rules
Created May 21, 2012 20:51 — forked from EnriqueVidal/current-rules
rubytij.org config
# Generated by iptables-save v1.4.10 on Sun Apr 22 03:00:29 2012
*filter
:INPUT DROP [59:1664]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [49:5928]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 4 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
@javierg
javierg / fines-comunidad-ruby-tijuana.md
Created April 17, 2012 17:58
fines-comunidad-ruby-tijuana
  1. Sin fines de lucro
  2. Moderación abierta. Administrador sólo quita el spam
  3. Compartir código bajo una cuenta de organización de Github
  4. El grupo es una democracia
  5. Cuando la democracia no es suficiente (empate etc), entra la meritocracia
  6. Comete errores (quien no los comete no aprende)
  7. Pide ayuda
  8. Diviértete, quien no disfruta lo que hace, lo hace mal...