Skip to content

Instantly share code, notes, and snippets.

# Prints out a tree like this (branches_height = 5) with a pedestal:
#
# x
# xxx
# xxxxx
# xxxxxxx
# xxxxxxxxx
# |
# ===
def render_tree(branches_height)

Keybase proof

I hereby claim:

  • I am duane on github.
  • I am drb (https://keybase.io/drb) on keybase.
  • I have a public key ASCYmQaidv-55raLIZDpt0uEeowdLoUG_gNrIhO_St-1Owo

To claim this, I am signing this object:

@duane
duane / bls.js
Last active April 13, 2016 01:48
$(".greenbar").removeClass("greenbar");
$('#cps_eeann_mwe_ft_det_occu tbody tr').each(function(i, el) {
var rows = $(el).find("td");
if (rows.length !== 6) {
return;
}
var stripAndParse = function(td){return parseFloat($(td).text().replace(/[$,]/g,''));},
men = stripAndParse(rows[3]),
women = stripAndParse(rows[5]);
if (!isNaN(men) && !isNaN(women)) {
fn parse_term<'i>(input: &'i mut ParserStream<'i>) -> Result<Option<LinearExpression>, String> {
let coef = Parser::parse_scalar(input).unwrap();
input.skip_whitespace();
let var = Parser::parse_identifier(input).unwrap();
match (coef, var) {
(Some(scalar), Some(var)) => Ok(Some(LinearExpression::term(var, scalar))),
(Some(scalar), None) => Ok(Some(LinearExpression::from(scalar))),
(None, Some(var)) => Ok(Some(LinearExpression::from(var))),
(None, None) => Ok(None)
}
@duane
duane / crash.scala
Created April 22, 2014 17:25
Scalac crash
def run() {
Thread.sleep(60000)
while (true) {
val start = System.currentTimeMillis()
val next = start + 60000
val numJobsToReport = numJobs
if (numJobsToReport != 0) {
val totalJobTimeToReport = totalJobTime
@duane
duane / gist:11187444
Created April 22, 2014 17:21
Scalac compiler problem
[error] /Users/duane/pinsights/pinsights-utils/src/main/scala/com/getpinsights/utils/WorkerAuditor.scala:70: unsupported pattern: (_: Exception) (a class scala.reflect.internal.Trees$Typed).
[error] This is a scalac bug. Tree diagnostics: (_: Exception){<null>}.
[error] case e: Exception => {
[error] ^
while compiling: /Users/duane/pinsights/pinsights-utils/src/main/scala/com/getpinsights/utils/WorkerAuditor.scala
during phase: patmat
library version: version 2.10.4
compiler version: version 2.10.4
reconstructed args: -classpath /Users/duane/pinsights/pinsights-utils/target/classes:/Users/duane/.m2/repository/com/typesafe/akka/akka-actor/2.0.5/akka-actor-2.0.5.jar:/Users/duane/.m2/repository/com/typesafe/config/0.3.1/config-0.3.1.jar:/Users/duane/.m2/repository/org/apache/curator/curator-recipes/2.2.0-incubating/curator-recipes-2.2.0-incubating.jar:/Users/duane/.m2/repository/org/apache/curator/curator-framework/2.2.0-incubating/curator-framework-2.2.0-i
@duane
duane / gist:9841277
Last active August 29, 2015 13:57
Duane, no! You'll make god cry!
val (unseenItems, changedItems, unchangedItems, status) = items.getData.grouped(3).map(_.toList).
foldLeft[(List[MediaFeedData], List[MediaFeedData], List[MediaFeedData], Map[String, Long])]((Nil, Nil, Nil, Map.empty))({
case ((unseenSoFar, changedSoFar, unchangedSoFar, statusMap), unseen :: changed :: unchanged :: Nil) => {
(
unseen :: unseenSoFar,
changed :: changedSoFar,
unchanged :: unchangedSoFar,
statusMap ++ Map(unseen.getId -> 0L,
changed.getId -> (changed.getComments.getCount.toLong - 1L),
unchanged.getId -> unchanged.getComments.getCount.toLong))
require 'formula'
class ScalaDocs < Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/files/archive/scala-docs-2.9.2.zip'
sha1 'b49ef500314d968ddbd683b64628925a747f35e5'
end
class ScalaCompletion < Formula
homepage 'http://www.scala-lang.org/'
@duane
duane / postgresql_9.1.9_plist_create.rb
Last active December 17, 2015 16:30
A script to generate a postgres launchctl plist for homebrew.
prefix = `brew --prefix`.chomp
var = "#{prefix}/var"
domain = "homebrew.mxcl.postgresql"
File.open("#{`brew --cellar postgresql`.chomp}/9.1.9/#{domain}.plist", "w") do |file|
file.write %Q{
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
@duane
duane / mysql_auth.md
Last active December 15, 2015 22:28
How to set root password for mysql

Note: the indented bits are intended to be copy/pasted. If you don't know your way around a unix system, and on top of that whatever weird design desisions ubuntu has implemented, it's very easy to mess them up.

Kill mysql and start it up in a completely unprivileged mode:

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

Now, mysqld_safe will block input, so you'll need to open a new terminal tab. Then, connect to mysql's meta database that includes auth information:

mysql -uroot mysql