Skip to content

Instantly share code, notes, and snippets.

View danielepolencic's full-sized avatar
💭
☸️

Daniele Polencic danielepolencic

💭
☸️
View GitHub Profile
function myClass(){}
myClass.prototype = {
myName: "some name" ,
settings: {name: 'random'}
};
m1 = new myClass();
m2 = new myClass();
m1.myName // some name
function Stream () {
this.fns = [];
}
Stream.prototype.push = function (element) {
var accumulator = this.fns[0](element);
for (var i = 1, len = this.fns.length; i < len; i++) {
if (accumulator) { accumulator = this.fns[i](accumulator); } else { break; }
}
};
module.exports = Foo
function Foo () {}
Foo.prototype.one = function (l) {
this.two(l);
};
Foo.prototype.two = function (l) {
if (l % 2) {
@danielepolencic
danielepolencic / gravity.md
Last active August 29, 2015 14:10
gravity language

The gravity language operates on a stack and has three basic operations:

  • Zi sets the i th element of the stack to zero
  • Ii increments the i th element by one
  • Ji,j compares the i th and j th elements and jumps if not equal

The stack looks like this:

+---+---+---+---+---+---+---+---+

The cube calendar consists of a plurality of cubes supported by a holder having month and day printed on the sides of the cubes. Assuming that you would like to build just the two cubes for the days, how do you print the numbers such as with just two cubes you are able to display all days for an entire month (from the 1st to the 31st)?

    +---+          +---+
    |   |          |   |
+---+---+---+ +---+---+---+---+
var cheerio = require('cheerio');
var $ = cheerio.load('<book><hc:title>Harry Potter</hc:title></book>');
console.log($('hc\\:title').text());
@danielepolencic
danielepolencic / flux.js
Last active August 29, 2015 14:23
Simple virtual dom loop
'use strict';
var create = require('virtual-dom/create-element');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var h = require('virtual-dom/virtual-hyperscript');
var raf = require('raf');
var el = void 0;
var previousVTree = void 0;
@danielepolencic
danielepolencic / video2gif.sh
Last active August 29, 2015 14:25
video to gif
#!/bin/bash
rm -rf frames
mkdir frames
ffmpeg -i "$1" -vf scale=320:-1:flags=lanczos,fps=10 frames/ffout%03d.png
convert -delay 5 -loop 0 -dither None -colors 128 "frames/ffout*.png" -fuzz "10%" -layers OptimizeFrame "$2"
rm -rf frames
# as seen on:
# http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
~/S/miniflux git:master ❯❯❯ phpunit --group failing ⬆ ✱
PHPUnit 4.7.6 by Sebastian Bergmann and contributors.
.
Time: 2.84 seconds, Memory: 16.25Mb
OK (1 test, 5 assertions)
~/S/miniflux git:master ❯❯❯ phpunit ⬆ ✱
PHPUnit 4.7.6 by Sebastian Bergmann and contributors.
@danielepolencic
danielepolencic / barclays_pdf_extraction.md
Created October 3, 2015 10:24
Barclays PDF extraction

Barclays PDF Extraction

  1. Download Tabula and import all the PDF you want to convert.
  2. Select the table(s) you want to export without paying attention to header and/or footer.
  3. Run the exported csvs through the following script:
    const parse = require('csv-parse')
    const read = require('fs').readFileSync;
    
    parse(read(process.argv[2]).toString(), {delimiter: ','}, (err, data) => {