Skip to content

Instantly share code, notes, and snippets.

View danielepolencic's full-sized avatar
💭
☸️

Daniele Polencic danielepolencic

💭
☸️
View GitHub Profile
@danielepolencic
danielepolencic / xpath.js
Last active December 7, 2015 11:33
xpath
function xpath(xpathExpression) {
'use strict';
const result = document.evaluate(xpathExpression, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
const nodes = [];
if (result) for (let i = 0, len = result.snapshotLength; i < len; i++)
nodes.push(result.snapshotItem(i));
function getScopes(root) {
var scopes = [];
function visit(scope) {
scopes.push(scope);
}
function traverse(scope) {
visit(scope);
if (scope.$$nextSibling)
@danielepolencic
danielepolencic / laptop.md
Created October 15, 2015 12:22
Setting up dev laptop

Setting up your laptop

Install XCode from the Mac App store (you need a valid apple account to do so). Open it up and accept the terms and conditions. Go to XCode > Preferences > Downloads and install from Components the Command Line Tools package. Install Homebrew with:

~$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

If the installation was successfull, verify:

@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) => {
~/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 / 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
@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;
var cheerio = require('cheerio');
var $ = cheerio.load('<book><hc:title>Harry Potter</hc:title></book>');
console.log($('hc\\:title').text());

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)?

    +---+          +---+
    |   |          |   |
+---+---+---+ +---+---+---+---+
@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:

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