Skip to content

Instantly share code, notes, and snippets.

@kenpusney
kenpusney / strong.rb
Created January 25, 2016 10:15 — forked from Yangff/strong.rb
strong type system for ruby
class Symbol
def [](*args)
a = [self, args, '[]']
a.instance_eval('@_type_flag = \'[]\'')
a
end
def <<(*ary)
a = [self, ary.flatten, '<']
a.instance_eval('@_type_flag = \'<\'')
a
@kenpusney
kenpusney / preprocessor_fun.h
Last active September 10, 2015 06:23 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```
/// Returns a length of the longest prefix of given string, which
/// `uint::from_str` accepts without a failure, if any.
pub pure fn scan_uint(s: &str) -> Option<uint> {
match str::find(s, |c| !('0' <= c && c <= '9')) {
Some(first) if first > 0u => Some(first),
None if s.len() > 0u => Some(s.len()),
_ => None
}
}
var empty_list = function(selector) {
return selector(undefined, undefined, true);
};
var prepend = function(el, list) {
return function(selector) {
return selector(el, list, false);
};
};
var head = function(list) {
;;;; Last modified : 2013-03-31 13:26:31 tkych
;; Usage:
;; (string-to-morse "Samuel")
;; => "... ._ __ .._ . ._.."
;; (morse-to-string "__ ___ ._. ... .")
;; => "MORSE"
;; (string-to-morse "Samuel Morse")
;; => error!! #\Space can't be converted to morse code.