Skip to content

Instantly share code, notes, and snippets.

View leocassarani's full-sized avatar

Leo Cassarani leocassarani

View GitHub Profile
@leocassarani
leocassarani / IRV.hs
Last active August 23, 2017 09:29
Instant-runoff voting
module IRV where
import Data.List (nub, sortBy)
import Data.Maybe (catMaybes, fromMaybe)
import Data.Ord (Down(..), comparing)
winner :: Eq a => [[a]] -> Maybe a
winner votes = do
let freqs = frequencies votes
top <- topCandidate freqs

Keybase proof

I hereby claim:

  • I am leocassarani on github.
  • I am leocassarani (https://keybase.io/leocassarani) on keybase.
  • I have a public key whose fingerprint is E1E2 2CB1 DD86 95C4 DA6A DDE3 6324 8FCF 2437 5713

To claim this, I am signing this object:

@leocassarani
leocassarani / line-v1.md
Created February 11, 2015 11:48
Archive of Geckoboard's legacy Line Chart widget documentation

Line Chart (V1)

The line chart visualisation is best suited for showing how a metric changes over time. An example use would be a number of visitors per day or sales per month.

You can specify labels for the X and/or Y axis of the chart.

Supported Sizes

  • 1 × 1
Name: v8
Description: v8 javascript engine
Version: 3.27.7
Cflags: -I/usr/include
Libs: /usr/lib/libv8.so -lrt
class WorkerScheduler
include Celluloid
def initialize(users)
@workers = users.map do |user|
Worker.new(user)
end
tick
end
@leocassarani
leocassarani / gist:4437585
Last active December 10, 2015 12:58
Text generated by trigram analysis of "Pride and Prejudice"
It is impossible for her daughter, and, without looking farther, it was given good principles, but left
to the fire and independence of his temper, whether he might say, she began to wish to see them, with
many expressions of gratitude for my part, I am dressed, and tell the same by all her Longbourn nieces.
Between the two girls of running as Elizabeth, really loved me, and I never heard any harm of her."
"No more have I," said Mr. Bennet, to understand by it that Mr. Bennet and Mrs. Bennet had no difficulty
in believing that neither her virtue nor her understanding than I can believe him capable of a broken
heart; and if they had. My friend has an excellent library."
No one admitted to the credit of their amiable neighbour, Miss Lucas, "but I shall hope to be left
@leocassarani
leocassarani / hash_literal.rb
Created May 26, 2012 17:28
Rbx Hash bytecode
============= :__script__ ==============
Arguments: 0 required, 0 post, 0 total
Arity: 0
Locals: 0
Stack size: 6
Lines to IP: 1: 0..28
0000: push_rubinius
0001: push_literal :User
0003: push_nil
# TL;DR: YOU SHOULD DELETE THIS FILE
#
# This file was generated by Cucumber-Rails and is only here to get you a head start
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
# visit pages, interact with widgets and make assertions about page content.
#
# If you use these step definitions as basis for your features you will quickly end up
# with features that are:
#
# * Hard to maintain
@leocassarani
leocassarani / gist:1407277
Created November 30, 2011 00:08
Generating Ruby documentation using static type inference

With the growing size of software frameworks and libraries, documenting code is becoming more and more important. This is especially true for dynamic languages such as Ruby, where type information is entirely absent and developers often rely on documentation provided by the authors of these frameworks and libraries. Nevertheless, the quality and completeness of code documentation is still very low even for many well known and widely used frameworks (e.g. Ruby on Rails).

The goal of this project is twofold. First, to write a byte-code evaluator that will analyse Ruby code and will attempt to infer the type of all parameters and return values for all methods of every class in the given project. Second, to use that information, together with contextual information such as class and method names, to annotate the methods with a brief summary and type signatures using documentation comments.

Thus an undocumented class such as:

class Project
  def find_by_name(name)
    [...]
@leocassarani
leocassarani / gist:1302681
Created October 20, 2011 23:13
Rubinius test failure
Process.groups gets an Array of the gids of groups in the supplemental group access list FAILED
Expected [12, 20, 33, 61, 79, 401, 402, 403, 404, 406, 409, 410, 411, 415, 416, 417]
to equal [12,
20,
33,
61,
79,
80,
81,
98,