Skip to content

Instantly share code, notes, and snippets.

Joakim Kolsjö joakimk

Block or report user

Report or block joakimk

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
@joakimk
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: {} })
socket.connect()
let channel = socket.channel("updates", {})
channel.join()
// Reload the app if it's out of date when it joins the websocket
let revision = null
@joakimk
joakimk / note.md
Created Dec 17, 2015
Fix for Oculus Rift DK2 positional tracking lean in out inverted
View note.md

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
joakimk / toniq_ui_ideas.md
Last active Nov 2, 2015
Toniq admin UI ideas
View toniq_ui_ideas.md

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
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])
broadcast_stats
{:ok, socket}
end
@joakimk
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__)
end
defmodule MessageForwarder do
use GenEvent
@joakimk
joakimk / solution.md
Last active Nov 24, 2015
Seeing "Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT" after upgrading from Rails 3 to Rails 4?
View solution.md

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
ActiveSupport::SafeBuffer
@joakimk
joakimk / tip.md
Last active Aug 29, 2015
Nginx "Bad Request" 400 error because of % in the body text?
View tip.md

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
joakimk / jocke_aliases_and_functions.sh
Created May 28, 2015
The terminal aliases and functions I somewhat regularly use (gist for easy use when pairing)
View jocke_aliases_and_functions.sh
# 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
joakimk / gist:5efe8d04e526d521e8c6
Last active Aug 29, 2015
Alternate heroku setup for circle
View gist:5efe8d04e526d521e8c6
echo -e "machine api.heroku.com\n login $HEROKU_USER\n password $HEROKU_API_KEY\nmachine code.heroku.com\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.
You can’t perform that action at this time.