Skip to content

Instantly share code, notes, and snippets.

@jacopofar
jacopofar / python_3_6_runtime_type_checking.py
Last active August 31, 2017 13:28
python 3.6 runtime type checking
#!/usr/bin/env python3
from typing import (Union,
Tuple,
Any,
TypeVar,
Type,
List)
def check_type(obj, candidate_type, reltype='invariant') -> bool:
@jacopofar
jacopofar / Git basics.ipynb
Created August 11, 2017 13:47
Git training examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jacopofar
jacopofar / subtitle_process.py
Created June 11, 2017 15:54
Process OpenSubtitles2012 dataset and produce a CSV file
import os
import gzip
import xml.sax
import csv
subs_dir = 'OpenSubtitles2012'
current_file = ''
current_movie_id = '???'
current_year = '???'

Keybase proof

I hereby claim:

  • I am jacopofar on github.
  • I am jacopofar (https://keybase.io/jacopofar) on keybase.
  • I have a public key whose fingerprint is A6E1 7CFC 0FE1 51E7 9D4B 94B1 59D9 FA5F F4CF 1F5A

To claim this, I am signing this object:

@jacopofar
jacopofar / send_more_money.js
Created December 21, 2016 11:55
SEND MORE MONEY
'use strict';
/**
Javascript (ES6) implementation of a puzzle: each letter is a digit (0-9) and we have to find values for the letters in SEND MORE MONEY such that:
1. replacing the letters with the correspondign digits the expression SEND + MORE = MONEY is true
2. the first digits of each word are not 0
*/
const leftpart1 = 'SEND'.split('');
const leftpart2 = 'MORE'.split('');
@jacopofar
jacopofar / python3 redis markov chain
Created November 3, 2016 10:47
redis markov chain adapted to Python3 and UTF-8 handling
"""
Functions for generating simple markov chains for sequences of words. Allows for scoring of
sentences based on completion frequency.
"""
import random
import redis
PREFIX = 'markov'
SEPARATOR=':'
STOP = '\x02'
FROM ubuntu:wily
#FROM phusion/baseimage:latest
#get the repo indexes
RUN apt-get update && apt-get -y upgrade
# system dependencies needed to install the libraries from pip
RUN apt-get install -y python-setuptools gcc python-dev libhdf5-dev libjpeg-dev zlibc zlib1g-dev
RUN easy_install pip
RUN pip install numpy
RUN pip install scipy
RUN pip install pillow
@jacopofar
jacopofar / POSfromDump
Created May 14, 2013 12:26
Extract Italian words POS tags froma Wiktionary XML dump
package generazione;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;