This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'english' | |
class FailedTransaction < StandardError; end | |
def log(color, message) | |
color_to_ansi = { | |
:bold => 1, :green => 32, :red => 31, :italic => 3 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require './attr_boolean' | |
class GloZellGreen | |
attr_boolean :has_milk?, :has_cereal? | |
attr_boolean :has_bathtub_filled_with_milk_and_cereal | |
def initialize(supplies = {}) | |
milk = supplies.fetch(:milk, 0) | |
cereal = supplies.fetch(:cereal, 0) | |
bathtub = supplies.fetch(:bathtub, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
# Opens a browser window showing the documentation for the given | |
# class or method on ruby-doc.org. | |
# | |
# Usage: | |
# | |
# instance.doc -> Goes to class documentation. | |
# instance.doc :method -> Goes to method documentation. | |
def doc(name = nil) | |
cls = self.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
module BlackJack | |
SUITS = [:spades, :hearts, :diamonds, :clubs] | |
FACES = [:jack, :queen, :king] | |
# Turns a symbol to an index. | |
SUIT_TO_NUM = {spades: 0, hearts: 1, diamonds: 2, clubs: 3} | |
CARD_TO_NUM = {ace: 1, jack: 11, queen: 12, king: 13} | |
CARD_TO_NUM_UNICODE = {ace: 1, jack: 11, knight: 12, queen: 13, king: 14} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(binding). | |
-export([create/1, create/2]). | |
% Shortcut for value/option. | |
create(Value, Options) -> | |
create(Options#{value => Value}). | |
% Regular string! | |
create(Value) when is_binary(Value) -> | |
#{type => literal, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number.prototype[Symbol.iterator] = function* () { | |
for (let i = 0; i < this; i++) { | |
yield i; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Build all Maven files and dump all of the jars into a directory. | |
""" | |
import os | |
import sys | |
import re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright 2013 Eddie Antonio Santos | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (sort) | |
-- Given a degree sequence, determines whether it is graphical. Returns a list | |
-- of steps from the base case to the original degree sequence. | |
graphical :: [Int] -> Maybe [[Int]] | |
graphical ds | even $ sum ds = graphical' ds [] | |
-- By the handshaking lemma, cannot be a graph with odd sum: | |
| otherwise = Nothing | |
graphical' ds previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from itertools import groupby | |
def k_sized_groups(sequence, k): | |
""" | |
Generates iterable groups with a maximum of size of K members from the | |
given sequence. | |
>>> [list(g) for g in k_sized_groups([1, 2, 3, 4], 2)] |