Skip to content

Instantly share code, notes, and snippets.

@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))
@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 / 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 / SmallVector.h
Created November 2, 2011 23:36
LLVM SmallVector
//===- llvm/ADT/SmallVector.h - 'Normally small' vectors --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the SmallVector class.
@duane
duane / gist:1371111
Created November 16, 2011 19:43
Type error in small haskell program
module Main where
import Graphics.Sketch
import Data.Array.Repa
import Data.Word
import Control.Monad
import System.Random
randomWord8 :: IO Word8
@duane
duane / gist:1474880
Created December 14, 2011 01:55
mutability not working?
use std;
fn poke(value: uint, index: uint, data: @mutable [mutable uint]) {
(*data)[index] = value;
}
fn main(_args: [str]) {
let vec = [mutable 4u];
std::io::println(#fmt["%u", vec[0]]);
poke(3u, 0u, @mutable vec);
#[link_name = ""]
#[link_args = "BAD LINKING"]
native mod c {
fn random() -> int;
}
@duane
duane / gist:1475365
Created December 14, 2011 05:14
A merge-sort implementation
fn merge_sort<copy a>(&&d: [mutable a]) {
fn merge<copy a>(&&data: [mutable a], &&temp: [mutable a], low: uint, middle: uint, high: uint) {
let resultI = low;
let tempI = low;
let destI = middle;
while tempI < middle && destI <= high {
if data[destI] < temp[tempI] {
data[resultI] = data[destI];
resultI += 1u;
destI += 1u;
#[cfg(target_os = "macos")]
native mod c {
fn mach_absolute_time() -> u64;
}
#[cfg(target_os = "macos")]
#[link_name=""]
#[link_args = "-framework CoreServices"]
native mod CoreServices {
@duane
duane / redw.lhs
Created December 27, 2011 11:10
Reddit aeson/bytestring
> {-# LANGUAGE OverloadedStrings #-}
This is the main driver of the program.
> module Main where
We need System.Environment for access command line arguments:
> import System.Environment (getArgs)