Skip to content

Instantly share code, notes, and snippets.

View xevix's full-sized avatar

Alejandro Wainzinger xevix

View GitHub Profile
@xevix
xevix / tomahawk_apiv1.py
Created September 11, 2011 01:27
Query Tomahawk for tracks using the built-in web API.
import urllib
import urllib2
import contextlib
import json
import time
# Get an opener
opener = urllib2.build_opener()
# Base URL with params for requesting a formtoken via a call to auth1 (GET)
#include <stdio.h>
#include <stdlib.h>
typedef struct Nodee {
void* value;
struct Nodee* prev;
struct Nodee* next;
} Node;
typedef struct Listt {
@xevix
xevix / rubylike_scala.scala
Last active November 18, 2015 15:03
Ruby'ish Scala
class Op[A]
case class EachOp[A]() extends Op[A]
case class CollectOp[A]() extends Op[A]
case class RubyIterator[B, A](iter: Iterator[A], op: Op[B]) {
def `do`(f: A => B): List[B] = {
op match {
case EachOp() =>
iter.foreach(f)
List.empty[B]
trait PlaceholderExample {
def process[A](f: A => Unit)
val set: Set[_ => Unit]
set.foreach(process(_)) // No Error
set.foreach(x => process(x)) // No Error
val process1 = process _
set.foreach(process1) // No Error
set.foreach(process _) // Error
trait ListContainer[A <: ListContainer[A]] {
this: List[A] =>
def takeOne = take(1)
}
class MyContainer extends ListContainer[MyContainer] {
this: List[MyContainer] =>
def takeTwo = takeOne :: takeOne :: Nil
import scala.collection.immutable.IntMap
import scala.language.higherKinds
object main {
def main(args: Array[String]): Unit = {
trait Container[M[_]] { def put[A](x: A): M[A]; def get[A](m: M[A]): A }
implicit val listContainer = new Container[List] { def put[A](x: A) = List(x); def get[A](m: List[A]) = m.head }
implicit val optionContainer = new Container[Some] { def put[A](x: A) = Some(x); def get[A](m: Some[A]) = m.get }
// Can't parametrize on general maps, since Container expects a parametrized type with 1 type parameter, maps generally take 2
@xevix
xevix / slick_as_try.scala
Created December 5, 2015 10:13
Slick asTry
// Dies with:
//
// Error:(151, 98) missing parameter type for expanded function
// The argument types of an anonymous function must be fully known. (SLS 8.5)
// Expected type was: scala.util.Try[?] => ?
// coffees.length.result.flatMap(_ => DBIO.failed(new Exception())).transactionally.asTry.map {
// ^
coffees.length.result.flatMap(_ => DBIO.failed(new Exception())).transactionally.asTry.map {
case Failure(e: Throwable) => "failed"
case Success(_) => "succeeded"
@xevix
xevix / gist:7a367017d69d3952e409
Last active December 25, 2015 02:10
ICMPLyrics
19 ooooxooooooxooo.v.ooooooxooooxoooo (82.133.91.37) 271.062 ms 262.427 ms 287.285 ms
20 ooxoooooxooooo.mmm.ooooooooxxoooxo (82.133.91.18) 262.883 ms 272.324 ms 277.339 ms
21 oooxoooooxooo.eeeee.oooxoooooxoooo (82.133.91.63) 289.099 ms 273.337 ms 288.960 ms
22 ooooxooxooox.rrrrrrr.ooooooxooooox (82.133.91.56) 261.431 ms 278.393 ms 254.542 ms
23 oxooooooxoo.rrrrrrrrr.oooxooooooxo (82.133.91.55) 287.949 ms 283.869 ms 281.962 ms
24 xoooxooooo.yyyyyyyyyyy.oooxooooxoo (82.133.91.58) 250.730 ms 265.093 ms 269.916 ms
25 ooxoooooxooooo.ccc.ooooooooxoooxoo (82.133.91.96) 273.542 ms 270.435 ms 272.161 ms
26 oooooxooo.hhhhhhhhhhhhh.oxoooxoooo (82.133.91.23) 273.479 ms 294.211 ms 297.685 ms
27 ooxooxoo.rrrrrrrrrrrrrrr.ooxoooxoo (82.133.91.49) 275.232 ms 287.565 ms 271.983 ms
28 oxoooxo.iiiiiiiiiiiiiiiii.oooxooxo (82.133.91.60) 270.243 ms 272.478 ms 271.520 ms
@xevix
xevix / coproduct_scala_worksheet.scala
Created January 8, 2016 14:20
Coproduct Scala Worksheet Fail
// From Shapeless `coproduct.scala`
sealed trait Animal
case class Cat(name: String, livesLeft: Int) extends Animal
case class Dog(name: String, bonesBuried: Int) extends Animal
case class Koala(name: String, leavesEaten: Int) extends Animal
import shapeless.syntax.std.tuple._
import shapeless._, syntax.singleton._
object ShapelessMain {
def main(args: Array[String]): Unit = {
val l = 23 :: "foo" :: true :: HNil
l(1)
val t = (23, "foo", true)
t(1)