Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
lsof -tn -i:$1 -sTCP:LISTEN | xargs kill
# coding: utf-8
require "ostruct"
require "fileutils"
require "pp"
require "pathname"
require "rake/loaders/makefile"
### Variables ###
@hisui
hisui / a.swift
Last active April 11, 2016 12:17
let a = [["a","b"],["x","y"]]
let b = a.enumerate().flatMap { (i, a) in a.enumerate().map { (i, $0.0, $0.1) } }
b.forEach { (i, j, e) in
print("a[\(i)][\(j)] = \(e)")
}
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
import scala.collection.immutable.SortedMap
import scala.util.Random
class WRR[+A](total: Int, map: SortedMap[Int, A]) {
require(!map.isEmpty)
def pick(rand: Random): A = map.until(rand.nextInt(total) + 1).last._2
}
object WRR {
def apply[A](e: (Int, A), a: (Int, A) *): WRR[A] = {
@hisui
hisui / Parsers.scala
Last active December 8, 2015 03:11
Push-Based(non-blocking) Parser Combinator
import scalaz._
import scalaz.iteratee.Iteratee._
import scalaz.iteratee._
import scalaz.iteratee.StepT.{Done, Cont}
import Scalaz._
import scala.util.{Try, Success, Failure}
case class ~[A, B](a: A, b: B)
struct EquatesByAddress: Equatable { let raw: AnyObject? }
func ==(lhs: EquatesByAddress, rhs: EquatesByAddress) -> Bool {
return lhs.raw === rhs.raw
}
import android.opengl.GLES20;
import android.view.Surface;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
public class SurfaceUtil {
class Coord private (val degree: Int) {
override def toString: String = degree + "deg"
}
object Coord {
def normalize(deg: Int): Int = if (deg < 0) normalize(deg + 360) else deg % 360
def apply(deg: Int): Coord = new Coord(normalize(deg))
}
import RxSwift
let Completed = NSError(domain: "Completed", code: 0, userInfo: nil)
class CountdownTimer {
private let publisher = PublishSubject<Int>()
private let signal: Observable<Int>
init(_ count: Int) {