Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@everpeace
everpeace / A.txt
Created March 15, 2012 15:13
Matrix Multiplication in Scalding.
1 2 3
1 2 3
1 2 3
@viktorklang
viktorklang / minscalaactors.scala
Last active March 25, 2024 19:01
Minimalist Scala Actors
/*
Copyright 2012-2021 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@travisbrown
travisbrown / tower-of-hanoi.scala
Created September 23, 2012 17:44
Solving the Tower of Hanoi at the type level
/**
* Type-level Tower of Hanoi
* by Travis Brown
*
* Note: not optimal, and probably won't work for some valid inputs.
* Tested with Scala 2.9.2 and Shapeless 1.2.3.
*/
import shapeless._, Nat._
@stew
stew / fizzbuzz.scala
Created November 14, 2012 20:55
fizzbuzz in the scala type system
package fizzbuzz
// This is church encoding of natural numbers
sealed trait Num {
def toInt : Int
override def toString = toInt.toString
}
final case object Z extends Num {
def toInt : Int = 0
@travisbrown
travisbrown / fizzbuzz-faster.scala
Created November 18, 2012 23:19
FizzBuzz in the type system (faster)
import shapeless._, Nat._
trait FizzBuzz[N <: Nat] {
type R3 <: Nat
type R5 <: Nat
def ti: ToInt[N]
def prev: List[String]
def d3: R3 =:= _0
def d5: R5 =:= _0
@willurd
willurd / web-servers.md
Last active July 23, 2024 12:11
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@ms-tg
ms-tg / scala_try_monad_axioms.scala
Last active May 28, 2022 03:48
Scala Try: monad axioms
import scala.util.{Try, Success, Failure}
def f(s: String): Try[Int] = Try { s.toInt }
def g(i: Int): Try[Int] = Try { i * 2 }
def unit[T](v: T): Try[T] = Success(v)
//val v = "1"
val v = "bad"
val m = Success(v)
@psttf
psttf / MatchTypes.scala
Last active December 28, 2015 18:29
Find values of the same types in HList
import shapeless._
import poly._
import shapeless.ops.hlist.FlatMapper
object am {
/**
* A type class that helps us partially apply a polymorphic binary function
* to some value and map the resulting function (which of course isn't
* literally a Poly1) over an HList.
@lossyrob
lossyrob / merge.scala
Created December 15, 2013 03:39
GeoTrellis 0.9 code snippet for merging rasters.
import geotrellis._
import geotrellis.source._
import geotrellis.raster._
import geotrellis.data.arg._
object Main {
def main(args:Array[String]):Unit = {
println("Merging...")
GeoTrellis.init(GeoTrellisConfig("/home/rob/data/sf/catalog.json"))