Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View pietro909's full-sized avatar

pietro909 pietro909

View GitHub Profile
@pietro909
pietro909 / Flexbox Mixins
Last active December 31, 2015 22:29
A simple collection of mixins for Less in order to use FlexBox layout effortlessly among different modern browsers.I won't support any old browser, as they can be upgraded for free and Chrome/Firefox are free and available for every device.thanks to http://the-echoplex.net/flexyboxes/ for the help
/* FLEX CONTAINER */
.display-flex() {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: -moz-box;
display: flex;
}
.flex-direction-row {
@pietro909
pietro909 / SLISW-IO-2.2.io
Created May 10, 2016 19:50
SLISW - IO - 2.2
old_div := Number getSlot("/")
Number / := method(den, if( den == 0, 0, self old_div(den)))
2/0 # => 0
4/2 # => 2
@pietro909
pietro909 / SLISW-IO-2.3.io
Created May 10, 2016 20:00
SLISW - IO - 2.3
a := list(list(1,2,3), list(4,5,6), list(7,8,9))
a flatten reduce(+)
@pietro909
pietro909 / SLISW-IO-2.4.io
Created May 10, 2016 20:10
SLISW - IO - 2.4
l = list(1,2,3,4,5)
l average := method(
s := self size;
if(
size==0,
0,
self reduce(+) / size
)
)
l average # => 3
@pietro909
pietro909 / SLISW-IO-2.5.io
Last active May 18, 2016 09:55
SLISW - IO - 2.5
Matrix := Object clone
Matrix dim := method(x, y,
self matrix := list();
for(1, 0, x - 1, 1,
row := list();
for(1, 0, y - 1, row push(0));
matrix push(row)
)
)
@pietro909
pietro909 / SLISW-IO-3.1.io
Created May 18, 2016 20:49
SLISW - IO - 3.1
OperatorTable addAssignOperator(":", "atPutNumber")
curlyBrackets := method(
r := Map clone
call message arguments foreach(arg,
r doMessage(arg)
)
r
)
{- OVERVIEW ------------------------------------------------------
A "Tree" represents a binary tree. A "Node" in a binary tree
always has two children. A tree can also be "Empty". Below I have
defined "Tree" and a number of useful functions.
This example also includes some challenge problems!
-----------------------------------------------------------------}
@pietro909
pietro909 / gulp-for-elm.js
Created September 24, 2016 17:55
Gulp for Elm, thanks to Stef from Slack channel
'use strict';
var gulp = require('gulp'),
http = require('http'),
st = require('st'),
exec = require('child_process').exec,
gutil = require('gulp-util'),
clear = require('clear'),
counter = 0;
@pietro909
pietro909 / defensive-approach-javascript.js
Last active October 28, 2016 08:33
Example of how to handle unknown input
function contains(c, s) {
var index = typeof s === 'string' ? s.indexOf(c) : -1;
return index > -1;
}
console.log(contains("hi", "there")); // false
console.log(contains("hi", "hi, all")); // true
console.log(contains("hi", 1)); // false
console.log(contains("hi", null)); // false
@pietro909
pietro909 / runtime-error-typescript.ts
Last active October 28, 2016 08:33
A runtime error in Typescript
function contains(c: string, arr: string) {
var index = arr.indexOf(c);
return index > -1;
}
console.clear();
console.log(contains("hi", "there")); // false
console.log(contains("hi", "hi, all")); // true
console.log(contains("hi", 1)); // doesn't compile
console.log(contains("hi", null)); // TypeError: Cannot read property 'indexOf' of null