Skip to content

Instantly share code, notes, and snippets.

@uri
uri / stack.exs
Last active October 30, 2017 14:12
Two implementations of a stack in Elixir; one using GenServer and the other with send, receive, and pids.
defmodule StackGenServer do
use GenServer
def start, do: GenServer.start(__MODULE__, [], name: __MODULE__)
def query, do: GenServer.call(__MODULE__, :query)
def pop, do: GenServer.call(__MODULE__, :pop)
def push(element), do: GenServer.call(__MODULE__, { :push, element })
def handle_call(:query, _from, stack), do: {:reply, stack, stack}
def handle_call(:pop, _from, [h|t]), do: {:reply, h, t}
def handle_call(:pop, _from, []), do: {:reply, nil, []}
def handle_call({ :push, element }, _from, stack), do: {:reply, [element | stack], [element | stack]}
@uri
uri / Makefile
Last active June 17, 2016 14:16
Useful Makefile for development convenience
start:
mysql.server start
redis-server &
stop:
mysql.server stop
redis-cli shutdown
clone-db:
bundle exec rake dev:db:branch_dup
@uri
uri / po_box_regex.rb
Created June 27, 2016 21:11
PO Box (Post office box) regular expression in ruby.
po_box_regex = /\A\b(?:p[.\s]?o?[.\s]?b?[.\s]?)\b(?:box)?|post{1}\s(?:office)?\s?(:?box|bin){1}\z/i
# Matches
#
# P. O. Box
# P.O.Box
# Post Box
# Post Office Box
# P.O.B
# P.O.B.
RabbitMQ 3.5.7. Copyright (C) 2007-2015 Pivotal Software, Inc.
## ## Licensed under the MPL. See http://www.rabbitmq.com/
## ##
########## Logs: /var/log/rabbitmq/zulip@localhost.log
###### ## /var/log/rabbitmq/zulip@localhost-sasl.log
##########
Starting broker... completed with 0 plugins.
=WARNING REPORT==== 15-Aug-2017::11:53:14 ===
@uri
uri / actor_tutorial.exs
Created October 25, 2017 03:02
An example of the actor pattern in Elixir.
@moduledoc """
This file showcases how the actor pattern works in elixir by using send/receive
to pass messages and spawn to create a separate state for an actor.
import ActorTutorial
Create a tally actor and send a message
tally = start_tally()
send tally, {:add, 5}

Keybase proof

I hereby claim:

  • I am uri on github.
  • I am urigorelik (https://keybase.io/urigorelik) on keybase.
  • I have a public key ASDEHGnt1RSfY-SIysyW8mRw4ajygprYOFJrT5ng_MLmbQo

To claim this, I am signing this object:

@uri
uri / action_controller_gem.rb
Created April 16, 2018 16:06
Test case for confusing default_headers initialization
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do