Skip to content

Instantly share code, notes, and snippets.

@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 / NOTES.md
Last active December 11, 2021 09:37
Personal notes

Docker on windows

  • default user is manager\containeradministrator
  • mounted volumes require a Modify permission given to Authenticated Users, otherwise move operations (user by nuget restore for example) fail. TODO: why normal write operation work even without that??

Nuget

  • mixing `` with packages.config doesn't work: they seem to be mutually exclusive.
@davide-romanini
davide-romanini / BaseRepository.java
Created April 15, 2011 07:43
BaseRepository that delegates to spring-data-jpa SimpleJpaRepository. Useful inside java ee 6 cdi container where you don't want to use spring ifrastructure.
public abstract class BaseRepository<T extends Object, ID extends Serializable>
implements JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
private @PersistenceContext EntityManager em;
private SimpleJpaRepository<T, ID> target;
protected EntityManager getEntityManager() {
return em;
}
@davide-romanini
davide-romanini / backup.py
Created April 4, 2018 10:02
redis backup skeleton
import redis
import json
import base64
def test_data(r, items=100):
r.flushall()
for i in range(1, items):
r.set("KEY:{}".format(i), "Nice value to backup {}".format(i))
def dump(r, out):
@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
@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 / 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: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 / 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:4995884
Last active December 13, 2015 23:59
Throttle.java
package throttle;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Throttle {
/**