Skip to content

Instantly share code, notes, and snippets.

View mossprescott's full-sized avatar

Moss Prescott mossprescott

View GitHub Profile
@mossprescott
mossprescott / gist:7d96067b651c67d7c3b2
Created July 2, 2014 18:04
Two styles for closing parens
// With dangling parens:
Let('tmp0,
read("cities"),
Let('tmp1,
makeObj(
"0" ->
Add(
Divide(
Multiply(
@mossprescott
mossprescott / gist:7819ae83d223b93a43b9
Created July 2, 2014 22:03
Fancy ExprOp phase, handling "range" array underneath Between
def ExprPhase: PhaseE[LogicalPlan, PlannerError, Option[BsonField], Option[ExprOp]] = lpBoundPhaseE {
type Input = Option[BsonField]
type Output = PlannerError \/ Option[ExprOp]
toPhaseE(Phase { (attr: Attr[LogicalPlan, Option[BsonField]]) =>
scanPara0(attr) { (orig: Attr[LogicalPlan, Input], node: LogicalPlan[Attr[LogicalPlan, (Input, Output)]]) =>
def emit(expr: ExprOp): Output = \/- (Some(expr))
// Promote a bson field annotation to an expr op:
def promoteField = \/- (orig.unFix.attr.map(ExprOp.DocField.apply _))
@mossprescott
mossprescott / WriterT.scala
Last active August 29, 2015 14:04
WriterT examples
// See http://stackoverflow.com/a/11951799
// Just Writer:
def calc1a: Writer[List[String], Int] = Writer("doing calc" :: Nil, 11)
def calc1b: Writer[List[String], Int] = Writer("other calc" :: Nil, 22)
val r1 = for {
a <- calc1a
b <- calc1b
@mossprescott
mossprescott / gist:b188efc35a0f51cca6c5
Created July 23, 2014 19:38
Building a Map from several mismatched Options
/*
Say you have a handful of options and need to build a single map containing a key for each non-empty value, with some transformation of each.
Here's one way to do it, is there a more elegant way?
*/
val o1: Option[Int]
val o2: Option[String]
val v3: Int
@mossprescott
mossprescott / cleanupMongo.js
Created August 24, 2014 21:05
Drop temp collections and run repairDatabase to recover unused space
// run with mongo shell:
//
// $ mongo cleanupMongo.js
//
// $ mongo
// > r2-ds045089:PRIMARY> load('cleanupMongo.js')
function dbSize() {
return db.stats().fileSize/(1024*1024) + " MiB";
@mossprescott
mossprescott / cors.html
Last active August 29, 2015 14:07
Simple test for query request with Destination header
<html>
<head>
<title>Simple CORS test</title>
<script type="text/javascript">
var req = new XMLHttpRequest()
// req.open("GET", "http://localhost:8080/metadata/fs/", true)
req.open("GET", "http://localhost:8080/query/fs/?q=select+*+from+zips+limit+10", true)
req.send()
@mossprescott
mossprescott / gist:17a30a1829c3516c3166
Created December 12, 2014 23:01
JTextField's InputMap (Mac OS X, JDK 1.8.0_20)
ctrl pressed A: select-all
ctrl pressed BACK_SLASH: unselect
ctrl pressed BACK_SPACE: delete-previous-word
ctrl pressed C: copy-to-clipboard
ctrl pressed DELETE: delete-next-word
ctrl pressed H: delete-previous
ctrl pressed INSERT: copy-to-clipboard
ctrl pressed KP_LEFT: caret-previous-word
ctrl pressed KP_RIGHT: caret-next-word
ctrl pressed LEFT: caret-previous-word
@mossprescott
mossprescott / gist:3086d6c31debfecd697a
Created December 12, 2014 23:19
Teaching Swing how text works on the Mac
if (scala.util.Properties.isMac) {
import java.awt.event.KeyEvent._
import javax.swing.KeyStroke.getKeyStroke
val cmd = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
val opt = java.awt.event.InputEvent.ALT_DOWN_MASK
val shift = java.awt.event.InputEvent.SHIFT_DOWN_MASK
val extraKeys = Map(
getKeyStroke(VK_X, cmd) -> "cut-to-clipboard",
@mossprescott
mossprescott / gist:1b81806462e0b13b3ecc
Created February 20, 2015 20:10
SimpleMaps don't match
[info] x plan select with wildcard and two fields
[error] 'Right($SimpleMap($Read(Collection("zips")),(function (__rez) {
[error] for (var __attr in (_)) if (_.hasOwnProperty(__attr)) __rez[__attr] = _[__attr];
[error] __rez.city2 = (_ != null) ? _.city : undefined;
[error] __rez.pop2 = (_ != null) ? _.pop : undefined;
[error] return __rez
[error] })(
[error] { })))' is Right but
[error] trees are not equal:
[error] Chain
city pop loc.0
boulder 100,000 81.0
a
1
city loc.0 loc.1 pop state