This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Graham Scan - Tom Switzer <[email protected]> | |
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0) | |
def turn(p, q, r): | |
return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0) | |
def _keep_left(hull, r): | |
while len(hull) > 1 and turn(hull[-2], hull[-1], r) != TURN_LEFT: | |
hull.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Jarvis March O(nh) - Tom Switzer <[email protected]> | |
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0) | |
def turn(p, q, r): | |
"""Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn.""" | |
return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0) | |
def _dist(p, q): | |
"""Returns the squared Euclidean distance between p and q.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Chan's Convex Hull O(n log h) - Tom Switzer <[email protected]> | |
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0) | |
def turn(p, q, r): | |
"""Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn.""" | |
return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0) | |
def _keep_left(hull, r): | |
while len(hull) > 1 and turn(hull[-2], hull[-1], r) != TURN_LEFT: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2011, Tom Switzer | |
// Under terms of ISC License: http://www.isc.org/software/license | |
/** | |
* Sorts an array of integers in linear time using bucket sort. | |
* This gives a good speed up vs. built-in sort in new JS engines | |
* (eg. V8). If a key function is given, then the result of | |
* key(a[i]) is used as the integer value to sort on instead a[i]. | |
* | |
* @param a A JavaScript array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.tixxit.levenshtein | |
import scala.math.min | |
object EditDistance { | |
def editDist[A](a: Iterable[A], b: Iterable[A]) = | |
((0 to b.size).toList /: a)((prev, x) => | |
(prev zip prev.tail zip b).scanLeft(prev.head + 1) { | |
case (h, ((d, v), y)) => min(min(h + 1, v + 1), d + (if (x == y) 0 else 1)) | |
}) last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -rupN js/src/config/Darwin.mk js-mine/src/config/Darwin.mk | |
--- js/src/config/Darwin.mk 2007-02-05 11:24:49.000000000 -0500 | |
+++ js-mine/src/config/Darwin.mk 2011-11-23 13:49:20.000000000 -0500 | |
@@ -46,7 +46,7 @@ | |
CC = cc | |
CCC = g++ | |
CFLAGS += -Wall -Wno-format | |
-OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DDARWIN | |
+OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DDARWIN -DHAVE_VA_COPY | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# pluck - Pluck some random lines from a file. | |
# | |
# This simple tool chooses a fixed number of random lines from a file and | |
# outputs them to stdout (in order of their line number). | |
# | |
function usage { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package spire.example | |
import spire.math._ | |
import Implicits._ | |
object EndoRingExample { | |
// An abelian group is a commutative monoid with an inverse. | |
trait AbGroup[A] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.tixxit | |
import shapeless._ | |
import Nat._ | |
final class Fizz | |
final class Buzz | |
trait FizzBuzzAux[A <: Nat, B <: HList] { | |
def apply(): List[String] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless._ | |
final class AnyRefCounter[L <: HList, N <: Nat] | |
object AnyRefCounter { | |
implicit def empty = new AnyRefCounter[HNil, Nat._0] | |
implicit def anyRef[H <: AnyRef, T <: HList, N <: Nat](implicit c: AnyRefCounter[T, N]) = new AnyRefCounter[H :: T, Succ[N]] | |
implicit def anyVal[H <: AnyVal, T <: HList, N <: Nat](implicit c: AnyRefCounter[T, N]) = new AnyRefCounter[H :: T, N] | |
def countRefs[L <: HList, N <: Nat](xs: L)(implicit c: AnyRefCounter[L, N], n: ToInt[N]): Int = n() | |
} |
OlderNewer