Skip to content

Instantly share code, notes, and snippets.

View sscarduzio's full-sized avatar

Simone Scarduzio sscarduzio

View GitHub Profile
@sscarduzio
sscarduzio / WordChart.php
Created July 9, 2012 14:37
Count word occurrences in a text file, the scalable way (suitable for HUGE files)
<?php
/**
* Counts words in a text files and outputs a chart of the most used.
*/
// Test code, run from CLI
// php WordChart.php freakingLongNovel.txt
$filename = $argv[1];
@sscarduzio
sscarduzio / Acceptor.java
Last active December 12, 2015 12:19
Pumping connections goes really fast, but sometimes it just hangs and is not able to process ANY more connections.
public void start() {
NetServer ns = vertx.createNetServer();
ns.setTCPNoDelay(true);
ns.setReuseAddress(true);
ns.connectHandler(new Handler<NetSocket>() {
public void handle(final NetSocket socket) {
socket.exceptionHandler(new Handler<Exception>(){
@Override
@sscarduzio
sscarduzio / Printer.java
Created February 14, 2013 08:58
This Quartz simple job does not fire ever.
import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import java.util.TimeZone;
import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobDetail;
@sscarduzio
sscarduzio / BinaryRedisCodec.java
Last active June 8, 2023 14:17
Binary codec for Lettuce (asynchronous redis client for Java)
package com.lambdaworks.redis.codec;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
/**
* A {@link RedisCodec} that handles binary keys and values.
* This is useful if you are storing non-UTF8 data in Redis
* such as serialized objects or multimedia content.
@sscarduzio
sscarduzio / gist:5466815
Created April 26, 2013 11:44
Ramki maven archetype freshly created project does not compile
$ mvn clean package
i[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Project - bbcmonitor 1.2
[INFO] ------------------------------------------------------------------------
Downloading: https://oss.sonatype.org/content/repositories/snapshots/io/vertx/vertx-core/2.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://oss.sonatype.org/content/repositories/snapshots/io/vertx/vertx-core/2.0.0-SNAPSHOT/maven-metadata.xml (356 B at 0.2 KB/sec)
Downloading: https://oss.sonatype.org/content/repositories/snapshots/io/vertx/vertx-core/2.0.0-SNAPSHOT/vertx-core-2.0.0-20130426.110906-777.pom
Downloaded: https://oss.sonatype.org/content/repositories/snapshots/io/vertx/vertx-core/2.0.0-SNAPSHOT/vertx-core-2.0.0-20130426.110906-777.pom (0 B at 0.0 KB/sec)
16.04 14:05:04 euler:/tmp/shit $ cd project/
16.04 14:05:04 euler:/tmp/shit/project $ ls
README.md build-and-run.sh pom.xml src
16.04 14:05:04 euler:/tmp/shit/project $ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Project - project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
@sscarduzio
sscarduzio / Node1
Last active December 17, 2015 11:49
vert.x cluster shared data not working
$ vertx run test.js -cluster
Starting clustering...
No cluster-host specified so using address 192.168.1.11
1.0
@sscarduzio
sscarduzio / gist:5690367
Created June 1, 2013 13:25
Enable MySQL general log in OSX
SET GLOBAL general_log = 'ON';
Query logs: /usr/local/var/mysql/<machine-hostname>.log
@sscarduzio
sscarduzio / rg.out
Created June 25, 2013 09:02
Stack trace from redgate with vert.x 2.0.0 CR2
An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler
in the pipeline did not handle the exception.
java.nio.channels.ClosedChannelException
at io.netty.channel.AbstractChannel$AbstractUnsafe.flushNow(AbstractChannel.java:683)
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush(AbstractChannel.java:654)
at io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:644)
at io.netty.channel.DefaultChannelPipeline$HeadHandler.write(DefaultChannelPipeline.java:1040)
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite0(DefaultChannelHandlerContext.java:716)
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:700)
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:692)
@sscarduzio
sscarduzio / test.py
Created October 25, 2013 13:56
grepFromString with caseSensitive=False never executes the body of the for beyond the "if caseSensitive" statement (line 12)
def grepFromFile(filename, string):
content = run('cat' + filename, capture=True)
return grep(content, string)
def grepFromString(haystack, needle, caseSensitive):
result = None
if(caseSensitive):
needle = needle.lower()
s = StringIO.StringIO(haystack)