Skip to content

Instantly share code, notes, and snippets.

@joakimk
joakimk / File.md
Created September 11, 2016 13:18
heroku: Could not connect to database to initialize transfer

If you're seeing this error, try heroku ps:scale web=0 then import the database again and run heroku ps:scale web=1 afterwards. Found nothing on google for this error, so posting this gist with the solution that worked for me. Could have been a temporary error too.

@joakimk
joakimk / socket.js
Last active August 22, 2016 06:45
An example of auto reload on deploy in an Elixir Phoenix app
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 December 17, 2015 09:22
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
joakimk / toniq_ui_ideas.md
Last active November 2, 2015 19:58
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
joakimk / channel.ex
Last active October 23, 2015 19:05
Phoenix channel status using an elixir agent. Will only work on a single server.
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 August 29, 2015 14:24
Simple example of using GenEvent to pass on messages
# 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 October 13, 2023 17:00
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
ActiveSupport::SafeBuffer
@joakimk
joakimk / tip.md
Last active August 29, 2015 14:23
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
joakimk / jocke_aliases_and_functions.sh
Created May 28, 2015 08:01
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'