Skip to content

Instantly share code, notes, and snippets.

@joakimk
joakimk / base_env.sh
Created February 7, 2013 12:57
Using unicorn with preload_app. Init script, unicorn config and base environment. (not used in production yet). ERB templates.
#!/bin/sh
UNICORN_CONF="/data/<%= @app_name %>/shared/config/unicorn.rb"
UNICORN_EXEC="bundle exec unicorn"
UNICORN_PID="/var/run/<%= @app_name %>/unicorn.pid"
UNICORN_MAX_RELOAD_WAIT_TIME=60000 # 60 seconds
RAILS_ENV="<%= @rails_env %>"; export RAILS_ENV
RACK_ENV="<%= @rails_env %>"; export RACK_ENV
APP_ROOT=/data/<%= @app_name %>/current
@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)

# Installer script for the Android development environment on MacOSX.
# This code is Public Domain. Have fun.
# Made by @joakimk.
DOWNLOAD_DIR = "~/Downloads/android"
INSTALL_DIR = "/usr/local/android"
system "mkdir -p #{DOWNLOAD_DIR}"
def check(part)
print part.gsub(/_/, ' ').capitalize + " y/n: "; STDOUT.flush
@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 / the_little_redis_book_notes.md
Created March 25, 2012 16:18
Sections of text from The Little Redis Book

Sections of text from The Little Redis Book


Alternatively (or in addition to snapshotting), Redis can run in append mode. Any time a key changes, an append-only file is updated on disk. In some cases it's acceptable to lose 60 seconds worth of data, in exchange for performance, should there be some hardware or software failure. In some cases such a loss is not acceptable. Redis gives you the option. In chapter 5 we'll see a third option, which is offloading persistence to a slave.


id = redis.hget('users:lookup:email', 'leto@dune.gov')

user = redis.get("users:#{id}")

@joakimk
joakimk / functional_core_imperative_shell.rb
Last active October 14, 2015 00:27
An example of "functional core, imperative shell" as far as I understand it. For more info about this concept, see https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell.
# Written for this gist, but inspired by production code (I haven't run this code).
# Imperative shell
class Timer
def initialize(record)
@record = record
end
def start
save_changes clock.start
@joakimk
joakimk / Example.md
Created November 29, 2012 10:52
More sane backtraces

Example image

@joakimk
joakimk / 0_how_to_run.sh
Last active October 11, 2015 18:58
Runnable minimapper example (you just need some version of ruby installed)
# Copy and paste this into a terminal:
gem install minimapper
gem install activemodel # required for Minimapper::Entity[::Rails] (you can use Minimapper::Entity::Core without it)
curl https://gist.github.com/joakimk/3904952/raw/56b592e6eaa5a0206bf9207b0ee53aa0114a53eb/minimapper_example.rb > minimapper_example.rb
ruby minimapper_example.rb
@joakimk
joakimk / Rakefile
Created October 2, 2012 11:24
Try to run no-rails rake tasks first and fallback to rails when none is found.
#!/usr/bin/env rake
# If the code below fails, uncomment this. There are no known issues now, but we had one.
#require File.expand_path('../config/application', __FILE__)
#Auctionet::Application.load_tasks
#require File.expand_path('../lib/tasks/no_rails', __FILE__)
#__END__
# Load all non-rails tasks.
path = File.expand_path('../lib/tasks/no_rails', __FILE__)
@joakimk
joakimk / gist:3738997
Created September 17, 2012 18:43
Single core cloud computing performance
# Very simple CPU test. Not ideal.
# Setup (where possible):
# Ubuntu 11.04
# apt-get install ruby # 1.8.7
# ci:jocke $ ruby -v
# ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
ruby -e 't=Time.now;100000000.times { 22%5 };puts Time.now-t'