Skip to content

Instantly share code, notes, and snippets.

@ianoc
ianoc / diff
Created November 16, 2019 17:21
diff applied
diff --git a/WORKSPACE b/WORKSPACE
index a76b6f6..4c140a2 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -15,7 +15,14 @@ scala_register_toolchains()
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
-scala_repositories()
+scala_repositories((
use tokio::io::AsyncRead;
use tokio::io::AsyncWrite;
use hyper::client::connect::Connected;
use hyper::client::connect::Destination;
use http::Uri;
use hyper::client::connect::Connect;
use futures::Future;
use std::io;
/// A wrapper around `Proxy`s with a connector.
@ianoc
ianoc / toJson.scala
Created March 13, 2016 21:00
thrift to json
import org.apache.thrift.transport.TIOStreamTransport
import org.apache.thrift.protocol.{TProtocol, TProtocolFactory, TSimpleJSONProtocol}
val protocolFactory = new TSimpleJSONProtocol.Factory
def toJson(t: MYTYPE): String = {
val buf = new java.io.ByteArrayOutputStream
val proto = protocolFactory.getProtocol(new TIOStreamTransport(buf))
MYTYPE.encode(t, proto)
val baseStr = new String(buf.toByteArray, "UTF-8")
@ianoc
ianoc / github.py
Created March 10, 2016 22:58
Open current file/line number on github and copy to clipboard
import os
import sublime, sublime_plugin
class GithubCommand(sublime_plugin.TextCommand):
def run(self, edit):
file = self.view.file_name()
dir = "/".join(file.split("/")[:-1])
gitRepo = os.popen('cd %s; git rev-parse --show-toplevel'%(dir)).read()[:-1]
branch = os.popen('cd %s; git rev-parse --abbrev-ref HEAD'%(dir)).read()[:-1]
@ianoc
ianoc / fpath.py
Created March 10, 2016 22:53
Locate path in repo
import os
import subprocess
from subprocess import PIPE
import sublime, sublime_plugin
class FpathCommand(sublime_plugin.TextCommand):
def run(self, edit):
file = self.view.file_name()
file_dir = "/".join(file.split("/")[:-1])
def getTiming(ebScaldVariant:String, idx: Int, runName: String, tp: TypedPipe[_]) = {
val ms = System.currentTimeMillis
val cntrs = execute(tp.filter(_ => false).toIterableExecution.getAndResetCounters.map(_._2))
val after = System.currentTimeMillis
val cpuMS = cntrs.get(StatKey("CPU_MILLISECONDS", "org.apache.hadoop.mapreduce.TaskCounter")).get
val gcMS = cntrs.get(StatKey("GC_TIME_MILLIS", "org.apache.hadoop.mapreduce.TaskCounter")).get
val millisMap = cntrs.get(StatKey("MILLIS_MAPS", "org.apache.hadoop.mapreduce.JobCounter")).get
(ebScaldVariant, idx, runName, cpuMS, gcMS, millisMap, after - ms)
}
@ianoc
ianoc / minimum.hs
Created January 2, 2016 22:16
Minimum app in haskell
import qualified Turtle as T
main :: IO ()
main = do
ln <- T.readline
putStrLn $ show ln
@ianoc
ianoc / readInput.hs
Last active January 2, 2016 22:08
Reading stdin without buffering
import qualified Turtle as T
import qualified System.IO as IO
import Control.DeepSeq
mergeUntilTwoBlankLines :: (() -> IO (Maybe String)) -> IO [String]
mergeUntilTwoBlankLines fn = do
rd <- fn ()
processFunc [] rd
where processFunc ("" : existing) (Just "") = return existing
processFunc existing (Just nxt) = do
@ianoc
ianoc / KMeansJob.scala
Last active September 29, 2015 17:56 — forked from azymnis/KMeansJob.scala
K-Means in scalding
import com.twitter.algebird.{Aggregator, Semigroup}
import com.twitter.scalding._
import scala.util.Random
/**
* This job is a tutorial of sorts for scalding's Execution[T] abstraction.
* It is a simple implementation of Lloyd's algorithm for k-means on 2D data.
*
* http://en.wikipedia.org/wiki/K-means_clustering
@ianoc
ianoc / tpeSelect.scala
Last active August 29, 2015 14:19
Tpe Info + Select
object exp {
sealed trait ExprTpe[T]
sealed trait ExprPrimitiveTpe[T] extends ExprTpe[T]
sealed trait ExprContainerTpe[T] extends ExprTpe[T] {
def mapping: List[(String, ExprTpe[_])]
}
case class ContainerTpe2[A, B](_1: ExprTpe[A], nme1: String, _2: ExprTpe[B], nme2: String) extends ExprContainerTpe[(A, B)] {
override def toString = s"""Type container of ${_1} and ${_2}"""