Skip to content

Instantly share code, notes, and snippets.

View melrief's full-sized avatar

Mario Pastorelli melrief

View GitHub Profile
val scanner = accumulo.connector.createScanner(tableName, new Authorizations())
val iteratorSetting = new IteratorSetting(Int.MaxValue, classOf[RowCounterIterator])
scanner.addScanIterator(iteratorSetting)
val iterator = scanner.iterator()
iterator.hasNext shouldEqual true
val entry = iterator.next()
entry.getValue.get().length shouldEqual 0
println(entry)
LongByteCodec.decode(entry.getKey.getRowData.toArray) shouldEqual daySubscriberProfiles.size
scanner.close()
class HasN a where
n :: a -> Int
data JobOne = JobOne Int
data JobTwo = JobTwo
data JobThree = JobThree Int
data JobDescriptionWithN = JobDescriptionWithNOne JobOne | JobDescriptionWithNThree JobThree
data JobDescription = JobDescriptionTwo JobTwo | JobWithN JobDescriptionWithN
@melrief
melrief / circeDecoderOption.scala
Created June 12, 2016 09:29
Problem with circe's Decoder[Option]
import cats.data.Xor
import io.circe._
sealed abstract class Predicate extends Product with Serializable
final case class Equal(int: Int) extends Predicate
final case class Bigger(int: Int) extends Predicate
case class Foo(opt: Option[Predicate])
package csvShapeless
import shapeless._, labelled.{ field, FieldType }, syntax.singleton._
import scala.util.{Try,Success,Failure}
case class Person(name: String, surname: String, age: Int)
object Main extends App {
@melrief
melrief / init_sbt_project.sh
Last active August 29, 2015 14:12
This is a simple script to create an sbt template project in a directory
#!/bin/bash -eu
#
# Set up a sbt project. This script requires sbt and bash :).
#
# usage:
# - mkdir <project_name>
# - cd <project_name>
# - ./<this_script_dir>/init_sbt_project.sh
#
# author: Mario Pastorelli <pastorelli.mario@gmail.com>
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE TupleSections #-}
{-
Parsing the output of the xrandr command. For example:
$> xrandr
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
@melrief
melrief / XRandR.hs
Last active August 29, 2015 14:08
XRandR parsing with parsec
{-
Parsing the output of the xrandr command. For example:
$> xrandr
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
eDP1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 309mm x 173mm
1920x1080 60.0*+ 59.9
1680x1050 60.0 59.9
1600x1024 60.2
1400x1050 60.0
@melrief
melrief / MyTestSuite.scala
Last active November 27, 2019 19:10
Problem of Spark with FunSuite and defaultParallelism
import org.scalatest.FunSuite
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
class MyTestSuite extends FunSuite {
val conf = new SparkConf()
.setAppName("My Spark test")
@melrief
melrief / vimrc
Created July 10, 2014 19:25
Set the current selection indent to the indent of the line above it with <C-Tab> in vim
function! IndentAsPrevLine()
python << EOF
import itertools as I
from vim import *
if current.range.start > 0:
def takewhile(pred,l): return ''.join(I.takewhile(pred,l))
prev_line = current.buffer[current.range.start - 1]
import scala.language.higherKinds
import scala.math.{pow}
import scalaz._
import Scalaz._
import scalaz.effect._
case class Point(_x : Double, _y : Double)
case class GameUnit(_health : Int, _position : Point)