Skip to content

Instantly share code, notes, and snippets.

@chandu
chandu / Extends.scala
Created July 5, 2018 08:02 — forked from rjsen/Extends.scala
Macro annotation to eliminate case class repetition
import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context
@compileTimeOnly("use macro paradise")
class Extends[T](defaults: Any*) extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro Extends.impl
}
object Extends {
@chandu
chandu / BinTreeIterator.scala
Created April 23, 2018 01:30 — forked from akihiro4chawon/BinTreeIterator.scala
Tree traversal comparison: stream vs explicit state stack
object BinTreeIterator {
sealed trait Tree
case class Node(v: Int, l: Tree, r: Tree) extends Tree
case object Leaf extends Tree
def toIterator(node: Tree): Iterator[Int] = {
def toStream(n: Tree): Stream[Int] = n match {
case Node(v, l, r) => v #:: toStream(l) #::: toStream(r)
case Leaf => Stream.empty
}
@chandu
chandu / FinanceDSL.scala
Created March 22, 2018 01:02 — forked from btlines/FinanceDSL.scala
FinanceDSL using type-classes
object FinanceDSL extends App {
trait PrettyPrint[A] {
def prettify(a: A): String
class Ops(a: A) {
def pretty: String = prettify(a)
}
}
object PrettyPrint {
@chandu
chandu / Application.scala
Created January 25, 2018 23:30
Spark Standalone - Asked to kill executor
package sparky
import org.apache.spark.scheduler._
import org.apache.spark.sql.SparkSession
import scala.math.random
object Application {
def runSpark(args: Array[String] ): Unit = {
val spark = SparkSession
@chandu
chandu / ShrinkAllPdfs.bat
Created May 15, 2017 01:27 — forked from xoofx/ShrinkAllPdfs.bat
Shrink all pdf files in a folder (Windows)
@echo off
REM Install Ghostscript 64bit from http://www.ghostscript.com/download/gsdnld.html
REM Shrink all pdfs files in the current directory where this script is run and output to the
REM compressed sub-folder
setlocal
set GS_BIN=C:\Program Files\gs\gs9.15\bin\gswin64c.exe
set GS_OUTPUT_DIR=compressed
mkdir %GS_OUTPUT_DIR%
for %%i in (*.pdf) do "%GS_BIN%" -dNOPAUSE -dBATCH -dSAFER -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -sDEVICE=pdfwrite -sOutputFile="%GS_OUTPUT_DIR%\%%i" "%%i"
const PageNotFoundComponent = {
template: `
<div class="alert alert-danger" role="alert">
<h1>Page {{notFoundRoute}} not found</h1>
We tried hard, but unfotunately could not find a page that matches your request. :(
</div>
`,
data() {
return {
notFoundRoute: ""
@chandu
chandu / browserify - bootstrap package.json
Last active August 29, 2015 14:06
browserify - bootstrap package.json
/*Code attribution: http://stackoverflow.com/questions/24827964/browserify-with-twitter-bootstrap#answer-24834257*/
{
"name": "...",
"version": "0.0.1",
"description": "...",
"repository": {
"type": "git",
"url": "..."
},
"browser": {
@chandu
chandu / dsaqdcs.md
Created August 25, 2014 03:10 — forked from v0lkan/dsaqdcs.md

Caveat

The tables in this cheatsheet only make sense after you study all thes mentioned data structures and algorithms below.

Do not memorize them, learn how the underlying algorithms work, read the source.

This cheat sheet is just a quick reference to give an broad brush strokes overview of how the most frequently-used data structures and algorithms relate to each other, in terms of time and space complexity.

{
"vars": {
"@gray-darker": "lighten(#000, 13.5%)",
"@gray-dark": "lighten(#000, 20%)",
"@gray": "lighten(#000, 33.5%)",
"@gray-light": "lighten(#000, 46.7%)",
"@gray-lighter": "lighten(#000, 93.5%)",
"@brand-primary": "#428bca",
"@brand-success": "#5cb85c",
"@brand-info": "#5bc0de",
var modules= require('modules');
var jquery = require(modules.jquery);
/// Do something with the jquery