Skip to content

Instantly share code, notes, and snippets.

View scabbiaza's full-sized avatar

scabbiaza scabbiaza

View GitHub Profile
@scabbiaza
scabbiaza / 1.function-composition.js
Last active June 12, 2017 10:16
Functional programming
// http://paqmind.com/posts/fluent-api-debunked/
var R = require("ramda");
var sales = [
{id: 1, price: "500"},
{id: 2, price: "1500"},
{id: 3, price: "750"},
{id: 4, price: "1750"},
{id: 5, price: "150"},
exports.adjustBy = curry((pred, adjustFn, array) => {
let i = findIndex(pred, array);
if (i >= 0) {
return adjust(adjustFn, i, array);
} else {
return array;
}
});
map(when(whereEq({id: "1"}), flip(merge)({name: "FOO"})));
@scabbiaza
scabbiaza / hanoi.js
Created March 3, 2016 11:23
hanoi game on generators
import {filter, head, range} from "ramda";
const TOWERS_COUNT = 3;
// Int -> Int -> Int
let getIntermidiateDest = (from, to) => head(range(0, TOWERS_COUNT).filter(i => i != from & i != to));
// Int -> Int -> Int -> {a}
function *hanoi(n, from, to) {
@scabbiaza
scabbiaza / isCreditCardNumberValid.hs
Created February 22, 2016 18:05
Learning haskell
import Data.Char
-- Double the value of every second digit beginning from the right.
-- Add the digits of the doubled values and the undoubled digits from the original number
-- Calculate the remainder when the sum is divided by 10
-- If the result equals 0, then the number is valid.
-- String -> [Int]
@scabbiaza
scabbiaza / connected-cell-in-a-grid.js
Created February 15, 2016 07:52
Hackerrank: 7 Days of JavaScript
var flatMatrix = matrix => matrix.reduce((a, b) => a.concat(b));
var isListEmpty = list => list.filter(i => i === 1).length === 0;
var emptifyByIndexes = (list, indexes) => list.map((item, index) => indexes.indexOf(index) >=0 ? 0 : item);
var getFirstNonZeroElementIndex = list => {
for (var key in list) {
if (list[key] === 1) return Number(key);
}
};
@scabbiaza
scabbiaza / var vs let.md
Last active January 21, 2016 14:13
PTF Training session. Frontend for Backend Developers.
function varTest() {
 var x = 31;
 if (true) {
   var x = 71;      // same variable!
   console.log(x);  // 71
 }   
 console.log(x);    // 71
}
@scabbiaza
scabbiaza / typography.less
Last active July 15, 2023 15:22
Typography. Vertical Rhythm.
// How it works: https://youtu.be/IbfsvI6dh4U
@textFontSize: 20px;
@lineHeight: 1.5rem;
// Set up font size and line-height
html {
font-size: @textFontSize;
}
@scabbiaza
scabbiaza / notes.md
Last active October 24, 2022 11:39
Quality Attributes for JS Frontend Application
@scabbiaza
scabbiaza / notes.md
Last active November 24, 2015 13:46
Notes from the Book "High Performance Javascript" by N. Zakas

The book i'm reading is from 2010, so i want to keep only things that are important now, in 2015, and add some comments about the current situation with having ES2015 and modern libs in place.

Loading and Execution

Every time a <script> tag is encountered, the page must stop and wait for the code to download (if external) and execute before continuing to process the rest of the page. JavaScript’s tendency to block browser processes, both HTTP requests and UI updates,

@scabbiaza
scabbiaza / gist:ecab1f18f5c168d3e9b5
Created September 1, 2015 09:20
Bind/unbind with namespaces
// handler for click event
var h1 = $("h6").bind("click", function () {
console.log('click handler');
});
// handler for click event with namespace
var h2 = $("h6").bind("click.namespace", function () {
console.log('click handler with namespace');
});
// click event result: