Skip to content

Instantly share code, notes, and snippets.

View gkthiruvathukal's full-sized avatar

George K. Thiruvathukal gkthiruvathukal

  • Loyola University Chicago, Argonne National Laboratory (ALCF)
  • Chicago, IL, USA, North America, Earth, ..., Universe
  • LinkedIn in/gkthiruvathukal
View GitHub Profile
@gkthiruvathukal
gkthiruvathukal / CaseClassSort.sc
Created February 6, 2015 03:58
Tuple Sort Scala Worksheet
val wlist = List("alpha", "gamma", "beta", "epsilon")
case class DerivedData(s : String, len : Int)
val tlist = wlist map { n => DerivedData(n, n.length) }
val sortedBy1 = tlist.sortWith( (l, r) => l.s < r.s)
println("sorted by component 1")
sortedBy1 foreach println
@gkthiruvathukal
gkthiruvathukal / gist:950fdeddafe1a68f5fb1
Created March 17, 2015 17:59
Getting inline abs() to work in Scala with sealed class + @inline
import scala.util._
sealed class Abs {
@inline def abs(x : Int) : Int = if (x < 0) -x else x
}
object gcd {
val c = new Abs
@gkthiruvathukal
gkthiruvathukal / fun.scala
Created March 17, 2015 18:20
GCD with nested function
import scala.util._
import math.abs
object gcd {
def euclid(x: Int, y: Int): Int = {
def euclidHelper(x : Int, y : Int) : Int = {
if (x == 0) y
else euclidHelper(y % x, x)
}
@gkthiruvathukal
gkthiruvathukal / sbt compile
Created May 4, 2015 17:03
scala-tdd-fundamentals output
quince:scala-tdd-fundamentals gkt$ sbt compile
[info] Loading project definition from /Users/gkt/Work/scala-tdd-fundamentals/project
[info] Updating {file:/Users/gkt/Work/scala-tdd-fundamentals/project/}scala-tdd-fundamentals-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.10/sbt_0.13/3.0.0/jars/sbteclipse-plugin.jar ...
[info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-plugin;3.0.0!sbteclipse-plugin.jar (1019ms)
[info] downloading https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-core/scala_2.10/sbt_0.13/3.0.0/jars/sbteclipse-core.jar ...
[info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-core;3.0.0!sbteclipse-core.jar (1757ms)
[info] downloading https://repo1.maven.org/maven2/org/scalaz/scalaz-core_2.10/7.0.2/scalaz-core_2.10-7.0.2.jar ...
[info] [SUCCESSFUL ] org.scalaz#scalaz-core_2.10;7.0.2!scalaz-core_2.10.jar(bundle) (4410ms)
import requests
r = requests.get("https://api.github.com/repos/gkthiruvathukal/st-hec/contents/hydra/dataserver.py")
r.status_code
b64data = r.json().get('content')
print(base64.b64decode(b64data))
create database testing;
use testing;
create table employee (id int4, name text);
import java.nio.file._
val p = FileSystems.getDefault().getPath(".", "filename.txt")
val text = Files.readAllLines(p)
val joined = String.join("\n", text)
@gkthiruvathukal
gkthiruvathukal / cloc-report.sh
Created January 29, 2016 16:54
Build timeline of CLOC/NCLOC by commit, by file, and in XML format
# OS X: brew install cloc
# %H gives us the full hash (commit ID) only in a list
for commit in $(git log --pretty=format:"%H"); do
git checkout $commit
cloc --by-file --xml .
done
@gkthiruvathukal
gkthiruvathukal / c9-setup-java8+sbt.sh
Created February 20, 2016 04:44
Setting up Java 8 + SBT on Cloud 9
# Java 8
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
# https support (kind of lame)
sudo apt-get install apt-transport-https
# SBT
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
@gkthiruvathukal
gkthiruvathukal / gist:4bb286f33f3966ecb9e9
Last active February 24, 2016 05:03
Scala multidimensional array (problems)
// This takes forever and seems to use a lot more memory than expected
Array.ofDim[Double](2048, 2048, 2048)
// This seems to work faster and uses less memory.
def get1d(d1 : Int, init : Double) = Stream.continually(init) take d1 toArray
def get2d(d1 : Int, d2 : Int, init : Double) = Stream.continually( get1d(d2, init) ) take d1 toArray
def get3d(d1 : Int, d2 : Int, d3 : Int, init : Double) = Stream.continually( get2d(d2, d3, init) ) take d1 toArray
// More testing is needed.