Skip to content

Instantly share code, notes, and snippets.

@cldellow
cldellow / LDA_SparkDocs
Last active February 16, 2016 18:40 — forked from jkbradley/LDA_SparkDocs
LDA Example: Modeling topics in the Spark documentation
/*
This example uses Scala. Please see the MLlib documentation for a Java example.
Try running this code in the Spark shell. It may produce different topics each time (since LDA includes some randomization), but it should give topics similar to those listed above.
This example is paired with a blog post on LDA in Spark: http://databricks.com/blog
Spark: http://spark.apache.org/
*/
import scala.collection.mutable
76 www.amazon.com P sophie the giraffe B000IDSLOG
4 www.amazon.co.uk P sophie the giraffe B000SOG7BY
2 www.diapers.com P sophie the giraffe 15640
2 www.amazon.com P sophie the giraffe B00RYW27QM
1 www.amazon.com P sophie the giraffe B000SOG7BY
@cldellow
cldellow / sampling-profiler.md
Last active October 7, 2019 06:43
A poor man's sampling profiler

So your JVM app is slow...

The background

Imagine that you've inherited this program:

import scala.util.Random

object SlowApp {
@cldellow
cldellow / gist:7699599
Created November 28, 2013 23:44
Exceptions and promises
import dispatch._
def func = Http(host("exaadsfadsfmple.com") OK as.String)
try {
val rv = func.flatMap { _ => Promise(1) }
rv() // Doesn't reach here, prints out message
println("I'll never get here")
} catch {
case e: Exception => println("I'll catch this, but you'll still see the JRE printing a stack trace for a BG thread")
}
@cldellow
cldellow / keyboardnav.js
Last active December 28, 2015 03:29
Patched keyboardnav.js: Improves performance of Keyboard Navigation (https://chrome.google.com/webstore/detail/keyboard-navigation/abcekjakjehkpheoaadhkjfcdodpjbgk/reviews) extension on pages with many links by using a DocumentFragment (https://developers.google.com/speed/articles/javascript-dom).
/*
Copyright 2010 xnoreq
*/
const HINT_CLASS = "chrome_keyboardnav_hint",
HINT_CLASS_A = "chrome_keyboardnav_hinta",
HINTS_ID = "chrome_keyboardnav_hints";
const KEY_ESC = 27, KEY_COMMA = 188, KEY_RETURN = 13;
@cldellow
cldellow / gist:7435827
Created November 12, 2013 18:09
Diff: Improves performance of Keyboard Navigation (https://chrome.google.com/webstore/detail/keyboard-navigation/abcekjakjehkpheoaadhkjfcdodpjbgk/reviews) extension on pages with many links by using a DocumentFragment (https://developers.google.com/speed/articles/javascript-dom).
74a75
> var fragment = document.createDocumentFragment();
77c78
< document.body.appendChild(hintsDiv);
---
> fragment.appendChild(hintsDiv);
92a94
> document.body.appendChild(fragment);
The Godfather:
(0, ('c47cdc01ae393cc1', 'The Godfather', 1285.2524694611532, 1996.0, 1996.0))
(1, ('14ad24bec9864311', 'The Godfather Part II', 247.03430466050014, 664.0, 2126.0))
(2, ('3f07609919cea6a1', 'Unforgiven', 66.8648447097107, 464.0, 2203.0))
(3, ('3d759a6cec209d51', 'Goodfellas', 52.01722828431214, 1069.0, 3324.0))
(4, ('3d8d7ee67be90ce1', 'Casino', 44.32755685131195, 582.0, 2429.0))
(5, ('fa57dfab448a0271', 'The Deer Hunter', 41.576119653738715, 437.0, 2244.0))
(6, ('b269bfba160411c1', 'The Good, the Bad and the Ugly', 39.582209420249114, 697.0, 2689.0))
(7, ('d79251b20619d5a1', 'Scarface', 35.78798419686481, 812.0, 2809.0))
@cldellow
cldellow / the-bauer-kitchen
Created February 15, 2013 16:15
Ah, the Internet.
<p>
<font size="5">
<font size="5">
<font size="5">
<font size="5">
<font size="5">
<font size="5">
<font size="5">
<font size="5">
<font size="5">
@cldellow
cldellow / gist:3018581
Created June 29, 2012 15:22
Load 10K items of type product, 100K items of type othertype, memory usage to facet the first type grows 10x
curl -XPUT 'http://localhost:9200/products/othertype/_mapping?pretty=true' -d'{
"othertype": {
"properties": {
"year": { "type": "long" },
"b": { "type": "boolean" }
}
}
}'
@cldellow
cldellow / dl.py
Created June 10, 2012 16:19
A poor man's download accelerator
import getopt, sys, os, re
optlist, args = getopt.getopt(sys.argv[1:], "c:")
if len(args) != 2:
print "usage: " + sys.argv[0] + " [-c cookie] <url> <file> | bash"
sys.exit(1)
url, file = args