Skip to content

Instantly share code, notes, and snippets.

@adanselm
adanselm / CustomDataFormatters
Created January 10, 2013 19:05
Content of ~/Library/Developer/Xcode/UserData/Debugger/CustomDataFormatters to be able to display juce::String from http://www.rawmaterialsoftware.com/juce.php in Xcode 4.4 debugger.
<?xml version="1.0" encoding="UTF-8"?>
<CustomDataFormatters
version = "1.0">
<SummaryFormatters>
<SummaryFormatter
formatString = "{(const char *)$VAR.text.data}:s"
type = "const class juce::String &amp;">
</SummaryFormatter>
<SummaryFormatter
formatString = "{(const char *)$VAR.text.data}:s"
@adanselm
adanselm / zshaliases
Created December 9, 2014 12:16
My aliases for Zsh : killall lookalike, rebuilding osx "open with" db, checking new files in mercurial changeset, etc.
# Check if Incoming pull has new files in its changeset
alias hgnf="hg in -p | grep -B1 'new file'"
# start postgres
alias pgstart="/usr/local/bin/pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start"
# Cleanup the "open with" list of OSX by rebuilding its db
alias rebuild-openwith="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user"
# Kill all processes containing the given string
@adanselm
adanselm / erlang_factorial
Created April 7, 2015 15:41
Example Erlang function to compute factorials (taken from wikipedia)
-module(fact).
-export([fac/1]).
fac(0) -> 1;
fac(N) when N > 0, is_integer(N) -> N * fac(N-1).
@adanselm
adanselm / phoenix_unittest
Created April 7, 2015 18:46
Example unit-test in elixir phoenix
test "get /api/users returns a list of users" do
users_as_json =
%User{first_name: "Bob", last_name: "Dylan", email: "bob@aol.com"}
|> Repo.insert
|> List.wrap
|> Poison.encode!
response = conn(:get, "/api/users") |> send_request
assert response.status == 200
@adanselm
adanselm / router.ex
Created June 17, 2015 09:20
A typical Phoenix router
defmodule SbSso.Router do
use Phoenix.Router
pipeline :api do
plug :accepts, ~w(json)
end
# /API section
scope "/api", alias: SbSso.Api, as: :api do
pipe_through :api
@adanselm
adanselm / generated_routes.txt
Created June 17, 2015 09:36
The routes created by our router
api_user_path GET /api/users SbSso.Api.UserController.index/2
api_user_path GET /api/users/:id SbSso.Api.UserController.show/2
api_user_path POST /api/users SbSso.Api.UserController.create/2
api_user_path PATCH /api/users/:id SbSso.Api.UserController.update/2
PUT /api/users/:id SbSso.Api.UserController.update/2
api_user_path DELETE /api/users/:id SbSso.Api.UserController.destroy/2
api_user_subscription_path GET /api/users/:user_id/subs SbSso.Api.SubscriptionController.index/2
api_user_subscription_path GET /api/users/:user_id/subs/:id SbSso.Api.SubscriptionController.show/2
api_user_subscription_path POST /api/users/:user_id/subs SbSso.Api.SubscriptionController.create/2
api_product_path GET /api/products SbSso.Api.ProductController.index/2
@adanselm
adanselm / router.ex
Last active August 29, 2015 14:23
Obesebird_api router
defmodule ObesebirdApi.Router do
use ObesebirdApi.Web, :router
pipeline :api do
plug :accepts, ["json"]
end
scope "/api", ObesebirdApi do
pipe_through :api
@adanselm
adanselm / prod.secret.exs
Last active August 29, 2015 14:23
Production configuration reading from heroku env
use Mix.Config
# In this file, we keep production configuration that
# you likely want to automate and keep it away from
# your version control system.
config :obesebird_api, ObesebirdApi.Endpoint,
secret_key_base: System.get_env("SECRET_KEY_BASE")
# Configure your database
config :obesebird_api, ObesebirdApi.Repo,
@adanselm
adanselm / .travis.yml
Last active August 29, 2015 14:23
Obesebird_api travis configuration
language: elixir
elixir:
- 1.0.4
otp_release:
- 17.4
addons:
postgresql: '9.3'
before_script:
- MIX_ENV=test mix do deps.get, deps.compile, ecto.create, ecto.migrate
deploy:
@adanselm
adanselm / scheduler.ex
Last active August 29, 2015 14:23
Scheduling recurring tasks with a GenServer
defmodule ObesebirdApi.Scheduler do
use GenServer
alias ObesebirdApi.Slot
alias ObesebirdApi.Tasks
require Logger
# Server
def init(args) do
case Process.send(self, :check, []) do