Skip to content

Instantly share code, notes, and snippets.

View sscarduzio's full-sized avatar

Simone Scarduzio sscarduzio

View GitHub Profile
@sscarduzio
sscarduzio / Main.scala
Created May 15, 2016 22:29
Cats Free Monad. One algebra, many interpreters.
/**
* Created by sscarduzio on 15/05/2016.
*/
package free
object Main extends App {
// Algebra
sealed trait KVStoreA[A]
@sscarduzio
sscarduzio / SearchService.scala
Created January 27, 2016 14:40
Refactor ensime-server indexer (excerpt)
// Proposed code
override def receive: Receive = {
// ... snip ...
for {
indexed <- Future.sequence(batch.map {
case (_, f) =>
if (!f.exists()) Future.successful(f -> Nil)
else searchService.extractSymbolsFromClassOrJar(f).map(f ->)
})
.recoverWith { case t: Throwable => log.error(s"failed to index batch of ${batch.size} files", t); Future.failed(t)}
@sscarduzio
sscarduzio / GenericMonadTransformer.scala
Last active December 21, 2015 01:49
Daniel's transformer won't work with future
package test
import scala.util.Try
import scalaz._
import scalaz.std.option._
import scalaz.std.list._
sealed trait CoPConst {
type Point[A]
}
@sscarduzio
sscarduzio / pom.xml
Created December 19, 2015 16:16
Maven configuration for enabling Elasticsearch integration tests (took me 2 hours)
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
@sscarduzio
sscarduzio / sbtmkdirs.sh
Last active July 13, 2016 12:48 — forked from alvinj/sbtmkdirs.sh
A shell script to create an SBT project directory structure
#!/bin/bash
#------------------------------------------------------------------------------
# Name: sbtmkdirs
# Purpose: Create an SBT project directory structure with a few simple options.
# Author: Alvin Alexander, http://alvinalexander.com
# Info: http://alvinalexander.com/sbtmkdirs
# License: Creative Commons Attribution-ShareAlike 2.5 Generic
# http://creativecommons.org/licenses/by-sa/2.5/
#------------------------------------------------------------------------------
@sscarduzio
sscarduzio / AWS Lambda Python ZIP packager
Last active February 16, 2018 18:55
When your python script has dependencies, you need to make a ZIP to upload in AWS Lambda.
#!/bin/bash
### NB: This script assumes you have set up your project in virtualenv!
# Configure here your python script with dependencies
ACTUAL_PYTHON_SCRIPT=rss.py
WORKDIR_SUFFIX="__LAMBDA_PACK_SCRIPT"
rm -rf $TMPDIR/*$WORKDIR_SUFFIX
WORKDIR=`mktemp -d --suffix $WORKDIR_SUFFIX`
@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 / 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 / relog.sh
Created August 24, 2014 21:20
BtWiFi_with_FON automatic login written as a bash script. I have this running every 10 minutes on my raspberry pi
#!/bin/bash
# CONF
DBG=true
RELOG_UNAME=your@email.com
RELOG_PASSW=xxxxxxxxxxxxxxx
# END CONF
@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) {}