Skip to content

Instantly share code, notes, and snippets.

View fmarani's full-sized avatar

Federico Marani fmarani

View GitHub Profile
@fmarani
fmarani / examples.scala
Created July 31, 2010 00:36
scala examples
// prime number generator
for (i <- 2 to 1000)
if((2 to i).find( j=> (i % j == 0 && i != j) ) == None)
println(i)
// function currying example
def matcher(haystack: List[Char])(needle: String) = {
haystack contains needle.charAt(0)
}
CREATE USER 'username'@'localhost' IDENTIFIED BY '...';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
GRANT SELECT, LOCK TABLES on Project_app_production.* to 'user'@'localhost';
SHOW GRANTS FOR 'root'@'localhost';
select * from mysql.user;
---
@fmarani
fmarani / monad.php
Created March 23, 2011 14:16
Monad in PHP?!
<?php
/**
* Monad boxing integer side effects
*
* @package default
* @subpackage default
* @author Federico Marani
**/
class IntegerBox
{
@fmarani
fmarani / md5chunks.py
Created May 18, 2011 14:54
calculate md5 hashes of chunks of a file, configurable block size
#!/usr/bin/env python
from optparse import OptionParser
import hashlib
import sys
parser = OptionParser()
parser.add_option("-b", "--blocksize", dest="blocksize", type=int, default=1024,
help="Specify blocksize", metavar="blocksize")
@fmarani
fmarani / pipeline.py
Created July 15, 2011 10:42
Transformation pipeline in Python
#!/usr/bin/env python
import itertools
import random
import string
import functools
# support functions
#Sample implementation of ireduce()
@fmarani
fmarani / language-detection.sh
Created December 13, 2011 23:38
poor man's language classifier
echo "this is a text in engish written only to demonstrate the validity of this method in selecting the right language" > corpus_en
echo "questo è un testo in italiano scritto solamente per dimostrare la validita di questo metodo nel selezionare il linguaggio voluto" > corpus_it
echo "questa è una prova di testo per testare la versione italiana" > test
(echo `cat corpus_en test | gzip | wc -c` en; echo `cat corpus_it test | gzip | wc -c` it) | sort -n | head -1
echo "this is a test for the english version"> test
(echo `cat corpus_en test | gzip | wc -c` en; echo `cat corpus_it test | gzip | wc -c` it) | sort -n | head -1
@fmarani
fmarani / offliner.py
Created January 19, 2013 16:55
some ideas about offline pre-computation of functions in python
import inspect
REGISTRY = []
CACHE = {}
def offline_runner():
for fn, kwargs in REGISTRY:
#print "OFFLINE", fn, kwargs
CACHE[(fn, str(kwargs))] = fn(**kwargs)
@fmarani
fmarani / bkk.py
Created November 29, 2014 17:24
very simple content tracker
#!/usr/bin/env python
import sys
import os
import dbm
import json
import uuid
print("BaKKit up")
try:
op = sys.argv[1]
@fmarani
fmarani / pyside-webkit.py
Created December 5, 2014 08:47
python webkit integration test
import sys
from PySide.QtCore import QObject, Slot, QTimer
from PySide.QtGui import QApplication
from PySide.QtWebKit import QWebView, QWebPage
import logging
html = """
<html>
<body>
@fmarani
fmarani / pyside-webkit-inspector.py
Created December 5, 2014 08:48
python webkit integration test - with inspector
import sys
from PySide.QtCore import QObject, Slot, QTimer, Qt
from PySide.QtGui import QApplication, QWidget, QSplitter, QVBoxLayout, QShortcut, QKeySequence
from PySide.QtWebKit import QWebView, QWebSettings, QWebInspector
html = """
<html>
<body>
<h1>Hello!</h1><br>