Skip to content

Instantly share code, notes, and snippets.

@ppurang
ppurang / REPL session
Created July 1, 2011 10:36 — forked from gseitz/REPL session
Create 1-line extractors for traits
scala> trait YouCantMatchMe
defined trait YouCantMatchMe
scala> object YesICan extends Traitor[YouCantMatchMe]
defined module YesICan
scala> def uncatchable_?(any: Any) = any match {
| case YesICan(uncatchable) => Some(uncatchable)
| case _ => None
| }
@ppurang
ppurang / .gitignore
Created June 5, 2012 14:20 — forked from karmi/.gitignore
Three Nodes and One Cluster: Demo of ElasticSearch's Distributed Features
.DS_Store
logs/
data/
*.html
@ppurang
ppurang / gist:3385731
Created August 18, 2012 09:51 — forked from sadache/gist:3382059
Play2 new plugin: File NonBlocking/Async API - Copying a file
"copy file" in {
val fileGenerator = Enumerator.repeat(new java.util.Date.getTime.toString + "\n").through(Enumeratee.take(1000))
//val fileGenerator = Enumerator.repeat(new java.util.Date.getTime.toString + "\n") &>> Enumeratee.take(1000)
val f = FileChannel("/tmp/testwrite.txt").delete.writing.create
val f2 = FileChannel("/tmp/testwrite2.txt").delete.writing.create
fileGenerator // generates data
.through(RichEnumeratee.binarize()) // binarizes data to write into File
@ppurang
ppurang / pr.md
Created August 20, 2012 21:24 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@ppurang
ppurang / AkkaKafkaMailboxTest.scala
Created October 4, 2012 09:54 — forked from stonegao/AkkaKafkaMailboxTest.scala
Akka 2.0 actors with Kafka backed durable mailboxes.
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.agent.Agent
import com.typesafe.config.ConfigFactory
import akka.event.Logging
import akka.actor.Props
import kafka.utils.Utils
import java.nio.ByteBuffer
def breakIf[T: ClassTag](assertion: => Boolean, args: NamedParam*): Unit =
if (assertion) break[T](args.toList)
// start a repl, binding supplied args
def break[T: ClassTag](args: List[NamedParam]): Unit = savingContextLoader {
val msg = if (args.isEmpty) "" else " Binding " + args.size + " value%s.".format(
if (args.size == 1) "" else "s"
)
// Run this with scala <filename>
/**
* A Two-phase commit Monad
*/
trait Transaction[+T] {
def map[U](fn: T => U): Transaction[U] = flatMap { t => Constant(fn(t)) }
def flatMap[U](fn: T => Transaction[U]): Transaction[U] =
FlatMapped(this, fn)
import akka.actor.Actor.Receive
import akka.actor.ActorContext
import akka.actor.ActorLogging
import akka.actor.Actor
import akka.event.LoggingAdapter
object MyLoggingReceive {
def apply(log: LoggingAdapter)(r: Receive)(implicit context: ActorContext): Receive = r match {
case _: MyLoggingReceive ⇒ r
/*
* Copyright (c) 2012, Lawrence Livermore National Security, LLC. Produced at
* the Lawrence Livermore National Laboratory. Written by Keith Stevens,
* [email protected] OCEC-10-073 All rights reserved.
*
* This file is part of the S-Space package and is covered under the terms and
* conditions therein.
*
* The S-Space package is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
@ppurang
ppurang / installation.md
Created March 25, 2019 08:48 — forked from natbusa/installation.md
Dell XPS for Ubuntu 18.04

Dell XPS for Ubuntu 18.04

Bios:

press F12 on the Dell startup screen

  • disable safe boot
  • Change SATA Operation from "RAID On" to "AHCI"
  • Enable Legacy Boot as well as UEFI

Install Ubuntu from USB drive

Instructions are here: https://www.ubuntu.com/download/desktop