Skip to content

Instantly share code, notes, and snippets.

View potix2's full-sized avatar
:octocat:

Katsunori Kanda potix2

:octocat:
View GitHub Profile
import org.apache.spark.sql.SQLContext
def etl(sqlContext: SQLContext, source: String, destination: String): Unit = {
val df = sqlContext.read.format("com.databricks.spark.csv").option("header", "true").load(source)
df.select("year", "model").write.format("com.databricks.spark.csv").save(destination)
}
// etl(new SQLContext(sc), "cars.csv", "newcars.csv")
val testContext = TestSQLContext()
@potix2
potix2 / gist:5e54e07e217b9feb3ab6
Created April 16, 2015 10:30
GCJ2015-D-small
package gcj2015;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class D {
@potix2
potix2 / gist:1df815621d76e7ad3c70
Created April 16, 2015 10:18
GCJ2015-C-Small
package gcj2015;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class C {
wget -r -k -np --user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53" http://examle.com/xxxx/yyyy
#!/bin/bash
# ssh-multi
# D.Kovalov
# Based on http://linuxpixies.blogspot.jp/2011/06/tmux-copy-mode-and-how-to-control.html
# a script to ssh multiple servers over multiple tmux panes
starttmux() {
if [ -z "$HOSTS" ]; then
@potix2
potix2 / TLP.scala
Created July 27, 2014 13:18
type-level-programming-in-scala
package com.potix2.tlp
import Bool._
import Nat._
//http://apocalisp.wordpress.com/2010/06/08/type-level-programming-in-scala/
sealed trait Bool {
type If[T <: Up, F <: Up, Up] <: Up
}
@potix2
potix2 / wordcount.clj
Created September 25, 2013 00:22
Lisp Meet Up #9
(def test-data "'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value ")
(->> (re-seq #"\w+" test-data)
(map #(.toLowerCase %))
(group-by identity)
(map (fn [[k v]] [k (count v)])))
@potix2
potix2 / fibonacci.scala
Created June 2, 2013 14:41
memoized fibonacci
class Memoize1[-T, +R](f: T => R) extends (T => R) {
private[this] val memorized = scala.collection.mutable.Map.empty[T, R]
def apply(x: T):R = {
memorized.getOrElseUpdate(x, f(x))
}
}
object Memoize1 {
def apply[T, R](f: T => R) = new Memoize1(f)
@potix2
potix2 / Chapter7.scala
Created May 26, 2013 23:19
TAPL Chapter7 - Lambda Calculus
import java.util.NoSuchElementException
/**
*
*
*/
abstract class Term
case class TmVar(info:Object, x:Int, n:Int) extends Term
@potix2
potix2 / Chapter4.scala
Created May 26, 2013 23:16
TAPL Chapter4 - Arithmetic Expression
/**
*
*
*/
abstract class Term
case class TmTrue(info: Object) extends Term
case class TmFalse(info: Object) extends Term
case class TmIf(info: Object, t1:Term, t2:Term, t3:Term) extends Term
case class TmZero(info: Object) extends Term
case class TmSucc(info: Object, t:Term) extends Term