Skip to content

Instantly share code, notes, and snippets.

guys, dudes, bros

I think you mean team...

I think you mean squad..

I think you mean gang...

I think you mean pals...

defmodule RequiredFields do
defmacro __using__(_opts) do
quote do
def new(attributes) do
Map.merge(%__MODULE__{}, attributes)
|> validate
end
def validate(struct) do
missing = missing_attributes(struct)
@tjheeta
tjheeta / json_api.ex
Last active August 29, 2015 14:22
First pass for Ecto -> Json API - WIP
defmodule JsonApi do
def filter_struct(obj) do
is_struct?(obj) or (is_list(obj) && is_struct?(Enum.at(obj,0)))
end
def is_struct?(obj) do
is_map(obj) && Map.get(obj, :__struct__) != nil
# ( obj.__struct__ == Ecto.Association.NotLoaded ||
end
def json_api(obj) do
@omnibs
omnibs / phoenix showdown rackspace onmetal io.md
Last active June 10, 2024 17:47
Phoenix Showdown Comparative Benchmarks @ Rackspace

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)

Binary/Bitstring Matching

Introduction

Binary matching is a powerful feature in Elixir that is useful for extracting information from binaries as well as pattern matching. This article serves as a short overview of the available options when pattern matching and demonstrates a few common usecases.

Uses

Binary matching can be used by itself to extract information from binaries:

@limhoff-r7
limhoff-r7 / authenticate.ex
Created June 3, 2015 19:09
Authenticate user using session or params (uses session keys stuff from Authlogic in Rails). **NOTE: this is does no authorization, another plug needs to be written to require conn.assigns[:authorized_user] is set or that they have permissions to read records**
defmodule Metasploit.Pro.Plugs.Authenticate do
import Ecto.Query, only: [from: 2]
import Plug.Conn
def init(configuration) do
configuration
|> Keyword.put_new(:single_access_token_parm, "single_access_token")
|> valid_configuration!
end
@openmailbox
openmailbox / my_server.rb
Last active August 16, 2025 15:58
Introductory Rack-compliant web server
# An example of a very simple, rack-compliant web server.
# This software is made available under the MIT License.
#
# Copyright (C) 2025 Brandon Rice
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@stevedomin
stevedomin / create_post.exs
Last active December 26, 2024 09:19
Using UUIDs as primary key with Ecto
defmodule MyBlog.Repo.Migrations.CreatePost do
use Ecto.Migration
def change do
create table(:posts, primary_key: false) do
add :id, :uuid, primary_key: true
add :body, :string
add :word_count, :integer
timestamps
@chrismdp
chrismdp / s3.sh
Last active August 4, 2025 07:29
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
@jonhoo
jonhoo / README.md
Last active July 19, 2021 10:49
Distributed RWMutex in Go