Skip to content

Instantly share code, notes, and snippets.

@davide-romanini
davide-romanini / gist:4995932
Last active December 13, 2015 23:59
ThrottleAspect.groovy
package throttle
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
import java.util.concurrent.FutureTask
import javax.inject.Named
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.Signature
@davide-romanini
davide-romanini / gist:4995968
Created February 20, 2013 14:39
TestThrottle.groovy
package throttle
@Named
class TestThrottle {
@Throttle(count = 5, periodMillis = 300000L)
public String authenticate(String user, String pass) {
// this block will be invoked no more than 5 times in 5 minutes
// if you reach the limit, thread will block until the period is expired
}
@davide-romanini
davide-romanini / ThrottleAspect.groovy
Created March 5, 2013 11:02
ThrottleAspect.groovy
package throttle
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit
import javax.annotation.PreDestroy
@davide-romanini
davide-romanini / gist:8fe3d049dc02d1058311
Created December 13, 2014 13:10
inducks_sqlite_schema.sql
-- per gli .import:
-- tail -n +2 # rimuove l'header
-- sed 's/.$//' # rimuove l'ultimo separator
CREATE TABLE inducks_storyversion (
storyversioncode varchar(19) PRIMARY KEY,
storycode varchar(19),
entirepages int(7),
brokenpagenumerator int(7),
brokenpagedenominator int(7),
brokenpageunspecified CHAR(1) CHECK(brokenpageunspecified IN ('Y','N')),
@davide-romanini
davide-romanini / inducks_sqlite.sql
Created December 19, 2014 23:29
INDUCKS sqlite schema
-- based on http://coa.inducks.org/inducks/isv/createtables.sql
-- TODO: FTI not implemented
CREATE TABLE inducks_storyversion (
storyversioncode varchar(19),
storycode varchar(19),
entirepages int(7),
brokenpagenumerator int(7),
brokenpagedenominator int(7),
brokenpageunspecified CHAR(1) CHECK(brokenpageunspecified IN ('Y','N')),
kind varchar(1),
@davide-romanini
davide-romanini / inducks_unpack.sh
Last active August 29, 2015 14:11
INDUCKS sqlite loader
#!/bin/bash
# imports inducks data files into sqlite db
# tested with:
# - UNRAR 5.00 beta 8
# - sqlite 3.8.2 2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d
# before running:
# wget http://coa.inducks.org/inducks/isv.rar
# wget https://gist.githubusercontent.com/davide-romanini/e92f7ce5c582f54a34ea/raw/ba042b6b0debed472519150cdf05093627c11d6a/inducks_sqlite.sql
# cat inducks_sqlite.sql|sqlite3 coa.sqlite
ISV_RAR="isv.rar"
@davide-romanini
davide-romanini / pynch.py
Created October 18, 2015 14:41
Zip pinch for python prototype
from struct import pack, unpack
from collections import namedtuple
import zlib
EOCD = 'PK\x05\x06'
CD = 'PK\x01\x02'
EOCDRecord = namedtuple( 'EOCDRecord', [
'signature',
'diskNumber',
'diskWithCentralDirStart',
@davide-romanini
davide-romanini / zipfileremote.py
Last active February 8, 2022 05:16
Python zip file working on remote files over http
"""
Read ZIP files over sliceable objects. This is a modified version
of the original python zipfile implementation.
The main use case is to provide an efficient way to read
even large zip files over remote sites allowing for RANGE
queries.
This work has been ispired by the pinch project
https://github.com/peterhellberg/pinch
@davide-romanini
davide-romanini / UnzipWrapper.php
Created February 19, 2016 16:30
Php unzip command wrapper
<?php
class Psr7PipeWrapper implements \Psr\Http\Message\StreamInterface
{
/**
*
* @var resource
*/
private $process;
@davide-romanini
davide-romanini / comic_enhance_gmic.gmic
Created February 25, 2016 12:35
Custom command for (vintage) scanned comics enhance. Requires gmic 1.6.9
#@gmic comic_enhance : unsharp_level=0 bg=255,255,255 black=0,0,0 white=255,255,255 noise_rm=3,3,1 bilateral=10,10,2 erode=0 desaturate=0
#@gmic : Applies a bunch of filters to better render scanned comics
#@gmic : - unsharp (default 0): enhance details, useful for blurry scans
#@gmic : - bg: background color to remove. This color is blended in divisor mode, useful for vintage comics
#@gmic : - black: black point used to adjust color curves
#@gmic : - white: white point used to adjust color curves
#@gmic : - noise_rm (3,3,1): uses -iain_iains_nr filter to smooth out colors. slow but effective.
#@gmic : - bilateral (10,10,2): uses -gimp_bilateral as a second smoothing step
#@gmic : - erode: uses -gimp_morpho with circular kernel and minimal size of 2 to "engrave" strokes
#@gmic : - desaturate: uses the -desaturate_luminosity filter for grayscale pages