Skip to content

Instantly share code, notes, and snippets.

joakimk / socket.js
Last active Aug 22, 2016
An example of auto reload on deploy in an Elixir Phoenix app
View socket.js
import {Socket} from "phoenix"
let socket = new Socket("/socket", { params: {} })
let channel ="updates", {})
// Reload the app if it's out of date when it joins the websocket
let revision = null
joakimk /
Created Dec 17, 2015
Fix for Oculus Rift DK2 positional tracking lean in out inverted

Writing this down in case it's useful for someone.

The reason why my oculus had inverted positional tracking (when I lean in, it moved me backwards in the 3d scene) was that my camera cable was broken. Ensure the little blue light is on when using the rift.

joakimk /
Last active Nov 2, 2015
Toniq admin UI ideas

What type of app?

A web UI, maybe a phoenix app, or something simpler.

Basic version: list failed jobs, allow you to retry or delete them.

Toniq.failed_jobs Toniq.retry(job) Toniq.delete(job)

joakimk / channel.ex
Last active Oct 23, 2015
Phoenix channel status using an elixir agent. Will only work on a single server.
View channel.ex
defmodule BroadcastChannel do
use Phoenix.Channel
def join(channel, auth_message, socket) do
socket = assign(socket, :client_version, auth_message["client_version"])
ClientStats.join(channel, socket.assigns[:client_version])
{:ok, socket}
joakimk / code.exs
Last active Aug 29, 2015
Simple example of using GenEvent to pass on messages
View code.exs
# In this example we're running jobs of some kind, and waiting for events if they finish okay or fail.
defmodule JobEvent do
def start_link do
{:ok, pid} = GenEvent.start_link(name: __MODULE__)
defmodule MessageForwarder do
use GenEvent
joakimk /
Last active Nov 24, 2015
Seeing "Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT" after upgrading from Rails 3 to Rails 4?

For us this turned out to be that we had cached html generated by the rails 3 app that had the ASCII-8BIT encoding, clearing all html caches fixed this.

To arrive at this, we first added this debug code:

# if you reuse this: ensure it matches the method in your version of rails
# as the method is overwritten by this monkeypatch

# config/initializers/debug_encoding_errors.rb
joakimk /
Last active Aug 29, 2015
Nginx "Bad Request" 400 error because of % in the body text?

If you have a body like this:

payload={"data": "5 %"}

Then nginx will most likely give you a 400 bad request error.

To get around this, encode the json with "x-www-urlencoded" encoding.

A web framework like rails will transparently decode "x-www-urlencoded" for you.

joakimk /
Created May 28, 2015
The terminal aliases and functions I somewhat regularly use (gist for easy use when pairing)
# Rails
alias sc='bundle exec rails console'
alias ss="bundle exec rails server"
alias rs='rake spec'
alias rsu='rake spec:unit'
alias rsua='rake spec:unit:all'
alias rsa='rake spec:all'
alias mig='rake db:migrate'
alias rsp='rake testbot:spec'
alias ref='script/refresh'
joakimk / gist:5efe8d04e526d521e8c6
Last active Aug 29, 2015
Alternate heroku setup for circle
View gist:5efe8d04e526d521e8c6
echo -e "machine\n login $HEROKU_USER\n password $HEROKU_API_KEY\nmachine\n login $HEROKU_USER\n password $HEROKU_API_KEY" > ~/.netrc && chmod 0600 /home/ubuntu/.netrc # We want to simply configure the API key, this seems easier than using the regular UI as that requires you to log in as a github user and assign yourself, etc.