Instantly share code, notes, and snippets.

View index.hbs
{{#ui-visibility class="ui segment masthead"
onBottomPassed=(action "mastheadOffScreen")
onBottomPassedReverse=(action "mastheadOnScreen") }}
<div class="ui container">
<h1>Hello, World!</h1>
/// Returns the line and column numbers for the beginning and the end of
/// this pair.
/// # Example
/// ```
/// # use std::rc::Rc;
/// # use pest;
/// # use pest::inputs::StringInput;
/// # #[allow(non_camel_case_types)]
View reference.rb
module Runtime
class Reference
attr_reader :object, :weight
def initialize(object, weight)
@object = object
@weight = weight
def self.create(object)

Weighted Reference Couting

Weighted reference counting is more efficient than traditional reference counting because you don't have to update the reference counted object every time a reference is taken (potentially meaning updating the object on the heap and blowing the processor cache). Weighted reference counting only updates the referenced object when a reference is dropped or when weight is exhausted. Weight Reference Counting is also really good for concurrent systems because the number of synchronisations needed is much lower than normal reference counting.

Algorithm overview:

Allocate a new reference counted object with a default weight (a tunable power of two - usually around 1 << 16 for a real implementation). An initial reference is allocated which points to the object and the weight value is copied into it. Every time the reference is cloned, the weight is split in two (shifting one bit to the right is the same as dividing by two) and one half allocated to the existing reference and one

# This script tries to handle `git push` when the local branch isn't
# configured to track a remote branch.
# First, if the branch already tracks a remote branch then it just calls
# `git push` and we're done.
# Second, if the branch doesn't track a remote branch and there is a
# remote called "origin" present then it just makes an assumption and
View fun_with_modules.rb
require "rubygems"
require "colorize"
def desc(msg)
puts "Description".colorize(:yellow)
puts "===========".colorize(:yellow)
puts msg.colorize(:white)
def example(body)
View jitter.ex
defp store_jitter received_at, delivered_at do
received_usec = Time.to_usecs received_at
delivered_usec = Time.to_usecs delivered_at
jitter_usecs = delivered_usec - received_usec
delivered_sec = delivered_at |> Time.to_secs |> trunc
delivered_5m = delivered_at |> Time.to_secs |> trunc |> rem 300
delivered_1h = delivered_at |> Time.to_secs |> trunc |> rem 3600
{:ok, _} = R.query [
["ZADD", namespace("jitter"), delivered_usec, jitter_usecs],
# I use this to install Elixir on our codeship instances for testing. YMMV.
# curl -O
# . ~/
# You can override your Elixir and Erlang versions from your shell when you call ./
View enumerable_skip.rb
module Enumerable
# Duck punch for Enumerable that adds skip() to bypass
# the first `n` elements of the enumerator.
# Use skip/take to retrieve a range of values from an enumerable
# without forcing the values into an array and using [].
# This is substantially faster for really big collections, but
# not so much for small ones. ie use at your own risk
# Also, skip provides superficially the same behaviour as drop,