Skip to content

Instantly share code, notes, and snippets.

View sscarduzio's full-sized avatar

Simone Scarduzio sscarduzio

View GitHub Profile
@Test
public final void testPubSubPongBug() throws Throwable{
final Jedis c = pool.getResource();
final String psubMessage = "bang";
JedisPubSub jps = new JedisPubSub() {
@Override
public void onUnsubscribe(String channel, int subscribedChannels) {}
@Override
public void onSubscribe(String channel, int subscribedChannels) {}
@sscarduzio
sscarduzio / streams.scala
Created October 20, 2014 13:30
scalaz-stream Dojo
/**
* Created by sscarduzio on 16/10/2014.
*/
object Scalaz extends App {
import scalaz.stream._
import scalaz.concurrent.Task
def fahrenheitToCelsius(d:Double) : Double = {
3d // who cares about actually converting..
@sscarduzio
sscarduzio / SplitTimeInterval.scala
Created December 9, 2014 10:24
[@tailrec] Split time interval in smaller interval (Scala and Joda Time)
import org.joda.time.format.DateTimeFormat
import org.joda.time._
import scala.annotation.tailrec
val timeWindow: Seconds = Seconds.seconds(Hours.hours(12).toStandardSeconds.getSeconds)
type Delta = (DateTime, DateTime)
def splitInterval(from: DateTime, to: DateTime, interval: Seconds): Seq[Delta] = {
@tailrec
def loop(_from: DateTime, intervalList: Seq[Delta]): Seq[Delta] = {
@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 / 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