Skip to content

Instantly share code, notes, and snippets.

@tompave
tompave / middleman_build.sh
Last active May 30, 2016 18:02
Build a Middleman site and commit it to an orphan master branch, see the related blog post for the setup: http://tommaso.pavese.me/2016/05/22/how-to-deploy-a-middleman-website-to-github-pages/
#!/bin/bash
middleman build &&
echo "--- middleman build complete"
git checkout master &&
echo "--- cleaning old build"
(ls -1 | grep -v 'build' | xargs rm -rf ) &&
@tompave
tompave / timing.exs
Last active August 20, 2016 15:44
Fun with Elixir macros and Streams
defmodule Timing do
def now do
:os.system_time(:milli_seconds)
end
# broken! the block is executed immediately
#
def ftime([do: block]) do
t0 = now
{ :ok, block, now - t0 }
@tompave
tompave / thread_memory_overhead.rb
Created March 14, 2018 11:13
Find the memory overhead of threads in Ruby
def memory_kb
`ps -o rss= -p #{Process.pid}`.chomp.to_i
end
MEM_LOG = "current memory: %{mem} kB (+%{incr})".freeze
THR_LOG = "New Thread!".freeze
current_mem = 0
loop do
m = memory_kb()
@tompave
tompave / actors_and_messages.rb
Created November 10, 2018 18:43
Actors and Messages in Ruby
require "colorize"
REGISTRY = {}
DEBUG = false
SLEEP = 0.5
def register(id)
mailbox = Queue.new
Thread.current[:process_id] = id
REGISTRY[id] = mailbox