Instantly share code, notes, and snippets.

View post_process_balances.php
<?php
while($line = fgets(STDIN)){
$line = trim($line);
list($advertiserid, $ts, $balance_cents) = explode("\t", $line);
$date = date('Y-m-d', $ts);
echo "$date\t$advertiserid\t$ts\t$balance_cents\n";
}
View PageViewGenerator.scala
package com.parthpatil
import java.net.ServerSocket
import java.io.PrintWriter
import util.Random
/** Represents a page view on a website with associated dimension data. */
class PageView(url : String, status : Int, country: String, browser: String, userID : Int)
extends Serializable {
override def toString() : String = {
View FinagleFutureTester.scala
import com.twitter.util.{ Future => TFuture, _}
object Tester extends App {
def test1(): Unit = {
implicit val timer: Timer = new ScheduledThreadPoolTimer()
val startTime = System.currentTimeMillis()
val longProcess: TFuture[String] = TFuture { Thread.sleep(1000); "done" }
longProcess.raiseWithin(Duration.fromMilliseconds(100))
.onSuccess { _ => val elapsed = System.currentTimeMillis() - startTime; println(s"long process Success, elapsed = $elapsed")}
View RedisContidionalQueue.scala
package com.parthpatil
import com.lambdaworks.redis._
import rx.lang.scala.Observable
import scala.concurrent.{Promise, Future, Await, ExecutionContext}
import scala.concurrent.duration._
import com.google.common.util.concurrent._
import java.util.concurrent.{TimeUnit, ExecutorService, Executors}
View RxRedis.scala
package com.parthpatil
import com.lambdaworks.redis.output.{KeyStreamingChannel, KeyValueStreamingChannel}
import com.lambdaworks.redis.pubsub.{RedisPubSubConnection, RedisPubSubAdapter, RedisPubSubListener}
import com.lambdaworks.redis.{MapScanCursor, RedisFuture, RedisClient}
import rx.lang.scala.Observable
import scala.concurrent.{Promise, Future, Await, ExecutionContext}
import scala.concurrent.duration._
//import scala.concurrent.ExecutionContext.Implicits.global
import com.google.common.util.concurrent._
View LogTailer.scala
package com.parthpatil
import java.io.File
import java.util.concurrent.LinkedBlockingQueue
import org.apache.commons.io.input._
import rx.lang.scala.Observable
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
View Json4sTest.scala
/**
* Make sure you include the following in your build.sbt
"org.json4s" %% "json4s-core" % "3.2.10",
"org.json4s" %% "json4s-jackson" % "3.2.10"
*/
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.JsonDSL._
case class Candidate(name:Option[String], age:Option[Int], party:Option[String])
View gist:8321035
2014-01-08 18:06:17,749 INFO [main] io.druid.server.initialization.PropertiesModule - Loading properties from runtime.properties
2014-01-08 18:06:17,781 INFO [main] org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 5.0.1.Final
2014-01-08 18:06:18,208 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class io.druid.server.initialization.ExtensionsConfig] from props[druid.extensions.] as [ExtensionsConfig{searchCurrentClassloader=true, coordinates=[], localRepository='/Users/parth/.m2/repository', remoteRepositories=[http://repo1.maven.org/maven2/, https://metamx.artifactoryonline.com/metamx/pub-libs-releases-local]}]
2014-01-08 18:06:18,833 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class com.metamx.emitter.core.LoggingEmitterConfig] from props[druid.emitter.logging.] as [LoggingEmitterConfig{loggerClass='com.metamx.emitter.core.LoggingEmitter', logLevel='info'}]
2014-01-08 18:06:18,895 INFO [main] io.druid.guice.JsonConfigurator - Loaded class[class io.drui
View gist:7864738
➜ hadoop_cql3_word_count git:(cassandra-2.0) ✗ ./bin/word_count
DEBUG 14:35:30,741 java.io.IOException: config()
at org.apache.hadoop.conf.Configuration.<init>(Configuration.java:227)
at org.apache.hadoop.conf.Configuration.<init>(Configuration.java:214)
at WordCount.main(Unknown Source)
INFO 14:35:30,794 output reducer type: cassandra
DEBUG 14:35:30,801 java.io.IOException: config(config)
at org.apache.hadoop.conf.Configuration.<init>(Configuration.java:260)
at org.apache.hadoop.mapred.JobConf.<init>(JobConf.java:341)
View hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#