Skip to content

Instantly share code, notes, and snippets.

José Valim josevalim

Block or report user

Report or block josevalim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View rules.exs
# Elixir v1.0
defmodule Rules do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@rules []
end
end
@josevalim
josevalim / 0_README.md
Created Sep 13, 2012
Sinatra like routes in Rails controllers
View 0_README.md

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

View shared_connection.rb
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
@josevalim
josevalim / phoenix showdown rackspace onmetal io.md
Last active May 16, 2019 — forked from omnibs/phoenix showdown rackspace onmetal io.md
Phoenix Showdown Comparative Benchmarks @ Rackspace
View phoenix showdown rackspace onmetal io.md

Comparative Benchmark Numbers @ Rackspace

I've taken the benchmarks from Matthew Rothenberg's phoenix-showdown, updated Phoenix to 0.13.1 and ran the tests on the most powerful machines available at Rackspace.

Results

Framework Throughput (req/s) Latency (ms) Consistency (σ ms)
View Gemfile
source :rubygems
gem "ruby-prof"
@josevalim
josevalim / watcher.sh
Last active Apr 18, 2019
A 1LOC bash script for re-running tests whenever a lib/ or test/ file changes keeping the same VM instance
View watcher.sh
# You will need fswatch installed (available in homebrew and friends)
# The command below will run tests and wait until fswatch writes something.
# The --stale flag will only run stale entries, it requires Elixir v1.3.
fswatch lib/ test/ | mix test --stale --listen-on-stdin
@josevalim
josevalim / 0_README.markdown
Created Jan 9, 2012
Hello world of Sinatra-like libraries on Elixir, Ruby and Node.js
View 0_README.markdown
@josevalim
josevalim / sample output
Created May 24, 2012 — forked from alco/sample output
Updated Elixir chat demo
View sample output
defmodule Chat.Client do
# In all of the following functions 'server' stands for the server's pid
def join(server) do
send server, :join
end
def say(server, message) do
send server, { :say, message }
end
@josevalim
josevalim / mix app.tree
Last active Jul 20, 2018
Sample output of the new "mix app.tree" and "mix deps.tree" tasks in a Phoenix project (using master). The first command shows the applications you will effectively need at runtime in production while "deps.tree" is your whole dependency tree, including compile time, dev and test dependencies.
View mix app.tree
$ mix app.tree
demo
├── elixir
├── phoenix
│ ├── elixir
│ ├── plug
│ │ ├── elixir
│ │ ├── crypto
│ │ └── logger
│ │ └── elixir
@josevalim
josevalim / authorize.ex
Last active Apr 29, 2018 — forked from jeremytregunna/authorize.ex
This looks horrible (formatter)
View authorize.ex
defmodule Api.Authorize do
alias Account.Models.User
def board?(board_id, %User{} = user, available_permissions, required_permissions) do
with(
{:ok, board} <- Tracker.Board.find(board_id),
true <- Tracker.OrganizationMembers.user_in_organization?(user.id, board.organization_id),
^required_permissions <-
Enum.to_list(
MapSet.intersection(
You can’t perform that action at this time.