Skip to content

Instantly share code, notes, and snippets.

View pbouzakis's full-sized avatar

Paul Bouzakis pbouzakis

View GitHub Profile
// OOPS VIOLATION OF LISKOV!! Bad bad
Rectangle {
width(val) = _width = val
height(val) = _height = val
area() = width() * height()
}
test_area(rect: Rectangle) {
rect.width(4)
@pbouzakis
pbouzakis / tennis_kata.ml
Last active November 22, 2017 18:28
OCaml Tennis Kata
(* Tennis Kata in OCaml! *)
type player = PlayerOne | PlayerTwo
type point = Love | Fifteen | Thirty
type score =
| Points of point * point
@pbouzakis
pbouzakis / index.js
Created November 18, 2014 16:40
requirebin sketch
var compose = require("fn.js").compose;
var pipeline = require("fn.js").pipeline;
var partial = require("fn.js").partial;
var insertCss = require("insert-css");
insertCss("body { padding: 20px } \
.selected { font-weight: bold; color: red; font-family: Consolas; font-size: 18px; }\
.important { color: blue }");
// string, string returns DomElement
@pbouzakis
pbouzakis / index.js
Created November 18, 2014 15:07
requirebin sketch
// Prototype of task guard implemented in a more functional style.
var Promise = require("q").Promise;
var pipeline = require("fn.js").pipeline;
var partial = require("fn.js").partial;
// STATE OF THE WORLD, CHANGES GO HERE:
var STATE;
function createState(isDisposed) {
@pbouzakis
pbouzakis / index.js
Created November 18, 2014 03:20
requirebin sketch
// Prototype of task guard implemented in a more functional style.
var Promise = require("q").Promise;
var pipeline = require("fn.js").pipeline;
var partial = require("fn.js").partial;
// STATE OF THE WORLD, CHANGES GO HERE:
var STATE;
function createState(isDisposed) {
if (length >= 3 && isIndeterminate) {
isIndeterminate = false;
} else if (length > 0 && length < 3 && !isIndeterminate) {
that.hasError(true);
} else {
that.isQueryTextInvalid(true);
that.hasError(false);
}
@pbouzakis
pbouzakis / gist:7efcfd06bcc9b4d98481
Created August 5, 2014 17:38
Monkey patching `applyBindingsToDescendants` to support insertion points.
ko.applyBindingsToDescendants = (function (original) {
return function (childBindingContext, element) {
var insertionNodes = ko.utils.domData.get(element, "insertionNodes");
original.apply(ko, arguments);
if (insertionNodes) {
transcludeInto(element, insertionNodes);
}
};
@pbouzakis
pbouzakis / gist:8f771ae454faa6762e04
Last active August 29, 2015 14:04
Playing around with macro's using sweet.js. Here is an attempt at sweetening privacy with private maps.
/*
Sweet.js macros for privacy sugar.
Below could be rewritten using es6 weakmaps.
*/
macro privacy {
rule {} => {
var id = ++privates.id
var privMap = {}
this.__id = id
privates[id] = privMap
// requirejs aka "AMD" module
define(["./utils", "./userService"], function (utils, userService) {
// everthing in here is my module
});
define(function (require) {
var utils = require("./utils");
form(data-bind="submit: signIn")
block content
+signInErrorMessage()
+signInInputs()
+signInSubmitButton()