Skip to content

Instantly share code, notes, and snippets.

View jorgeortiz85's full-sized avatar

Jorge Ortiz jorgeortiz85

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jorgeortiz85 on github.
  • I am jorge (https://keybase.io/jorge) on keybase.
  • I have a public key whose fingerprint is 6BBB 3DAF 4B48 4133 E7CC A2E0 18C2 FC59 5D5C 0620

To claim this, I am signing this object:

@jorgeortiz85
jorgeortiz85 / frequency-test.rs
Last active December 25, 2015 11:29
Measuring kernel interrupt frequencies in Rust. Based on http://www.advenage.com/topics/linux-timer-interrupt-frequency.php
use std::libc::{c_int, c_ulong, c_void, exit, puts};
struct timeval {
tv_sec: i64,
tv_usec: i64
}
struct itimerval {
it_interval: timeval,
it_value: timeval
import com.twitter.util.{Duration, Future, FuturePool, Try}
import java.util.concurrent.{LinkedBlockingQueue, ThreadPoolExecutor, TimeUnit}
val poolSize = 4
val queue = new LinkedBlockingQueue[Runnable]()
val executor = new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS, queue)
val futurePool = FuturePool(executor)
def doWork(n: Int): Int = {
Thread.sleep(1000)
import com.twitter.util.{Duration, Future, FuturePool, Try}
import java.util.concurrent.{LinkedBlockingQueue, ThreadPoolExecutor, TimeUnit}
val poolSize = 4
val queue = new LinkedBlockingQueue[Runnable]()
val executor = new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS, queue)
val futurePool = FuturePool(executor)
def doWork(n: Int): Int = {
Thread.sleep(1000)
java.lang.NullPointerException
at scala.tools.nsc.symtab.Symbols$Symbol.baseTypeSeqLength$1(Symbols.scala:1003)
at scala.tools.nsc.symtab.Symbols$Symbol.isLess(Symbols.scala:1006)
at scala.tools.nsc.symtab.Types$Type.baseTypeIndex(Types.scala:769)
at scala.tools.nsc.symtab.Types$CompoundType.baseType(Types.scala:1377)
at scala.tools.nsc.symtab.Types$TypeRef.baseType(Types.scala:1915)
at scala.tools.nsc.symtab.Types$class.firstTry$1(Types.scala:4664)
at scala.tools.nsc.symtab.Types$class.scala$tools$nsc$symtab$Types$$isSubType2(Types.scala:4821)
at scala.tools.nsc.symtab.Types$$anonfun$isSubType$1.apply$mcZ$sp(Types.scala:4536)
at scala.tools.nsc.symtab.Types$undoLog$.undoUnless(Types.scala:143)
@jorgeortiz85
jorgeortiz85 / CompanionProvider.scala
Created June 17, 2012 03:22
dependent method types
trait CompanionProvider[T] {
type CompanionT
def provide: CompanionT
}; object CompanionProvider {
def apply[T](implicit c: CompanionProvider[T]): c.CompanionT = c.provide
}
object Foo {
def foo = "fooooo"
@jorgeortiz85
jorgeortiz85 / DepFun.scala
Created May 7, 2012 00:12
dependent method types
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class Outer { class Inner }
defined class Outer
scala> trait DepFun { def apply(x: Outer): x.Inner }
defined trait DepFun
@jorgeortiz85
jorgeortiz85 / JavaConversionsEvil.scala
Created January 22, 2012 12:44 — forked from seanparsons/gist:1656555
scala.collection.JavaConversions is evil
import scala.collection.JavaConversions._
case class Foo(s: String)
val map: Map[Foo, String] =
Map(
Foo("a") -> "a",
Foo("b") -> "b")
val v = map.get("a") // should be a type error, actually returns null
@jorgeortiz85
jorgeortiz85 / FK.scala
Created September 21, 2011 16:29
attempt at newtype in Scala for FKs
class FK[A] extends StaticAnnotation
class User
class Checkin
object Main {
def fetch[A](id: Int @ FK[A]): A = null.asInstanceOf[A]
def main(args: Array[String]): Unit = {
val id: Int @ FK[Checkin] = 10
@jorgeortiz85
jorgeortiz85 / process.scala
Created August 16, 2011 23:29
Scala Process Library
import scala.sys.process._
import java.io._
// Run a Process, return the output as a String
Process("echo foo") !!
// Run a Process, pipe in some input, and return the output as a String
Process("cat") #< (new ByteArrayInputStream("foobar".getBytes("UTF-8"))) !!
// Run a Process, pipe in some input, and pipe the output to a Array[Byte]