Skip to content

Instantly share code, notes, and snippets.

trait Budget {
def events: Seq[Transaction]
}
@hohonuuli
hohonuuli / BudgetApp.scala
Last active December 19, 2017 22:10
Scala class for Medium article
import java.time.{Duration, Instant}
object BudgetApp extends App {
val budget = CurrentBudget
val endDate = Instant.now.plus(Duration.ofDays(365))
def filter(s: Stream[Transaction]): Stream[Transaction] = s.takeWhile(i => i.date.isBefore(endDate))
def money(s: Stream[Transaction]): Double = s.last.accumulatedValue
val sum = budget.events.map(_.stream) // Convert each transaction into a stream
@hohonuuli
hohonuuli / BudgetPlot.scala
Created December 19, 2017 22:26
Scala class for medium article
import java.time.{Duration, Instant}
object BudgetPlot extends App with scalax.chart.module.Charting {
val budget = CurrentBudget
val endDate = Instant.now.plus(Duration.ofDays(365))
def filter(s: Stream[Transaction]): Stream[Transaction] = s.takeWhile(i => i.date.isBefore(endDate))
val timeseries = new BudgetTimeSeries
budget.events
import java.time.Instant
trait Transaction {
def label: String
/** The amount of money in the transaction */
def value: Double
/** When this transaction occurs */
@hohonuuli
hohonuuli / CurrentBudget.scala
Last active December 19, 2017 23:38
Example for Medium article
import java.time.{Duration, LocalDate, Instant, ZoneId}
object CurrentBudget extends Budget {
// Helper function. Creates an Instant from dates like "2017-12-19"
implicit def toInstant(s: String): Instant = LocalDate.parse(s)
.atStartOfDay(ZoneId.systemDefault())
.toInstant
override def events: Seq[Transaction] = Seq(
@hohonuuli
hohonuuli / BudgetTimeSeries.scala
Last active December 19, 2017 23:39
Scala class for Medium article
import java.time.Instant
import scala.collection.mutable
import scilube.Matlib
class BudgetTimeSeries {
private[this] val series = new mutable.TreeMap[Instant, Double]
def addToSeries(events: Seq[Transaction]): Unit = {
import java.time.temporal.{ChronoField, TemporalAdjusters}
import java.time.{Duration, Instant, ZoneId}
/**
* A OneTime transaction does not reoccur in our model.
*/
case class OneTime(label: String,
value: Double,
date: Instant) extends Transaction {
public class Sample1 {
// --- Native methods
public native int intMethod(int n);
public native boolean booleanMethod(boolean bool);
public native String stringMethod(String text);
public native int intArrayMethod(int[] intArray);
// --- Main method to test our native library
@hohonuuli
hohonuuli / csiro.txt
Last active February 28, 2018 05:18
Dumping ground to share info between networks
>> ffprobe -loglevel quiet -show_streams -show_format -show_error -print_format json C01_2017_S027_S003_T002.MOV
# NOTES: File looks good. Has creation-time atom
{
"streams": [
{
"index": 0,
"codec_name": "pcm_s24le",
"codec_long_name": "PCM signed 24-bit little-endian",
"codec_type": "audio",
"codec_time_base": "1/48000",
@hohonuuli
hohonuuli / Dockerfile
Created May 11, 2018 20:05
Dockerfile for a scipy setup using jupyter
FROM ubuntu
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
curl \
cmake \
&& rm -rf /var/lib/apt/lists/*
RUN curl -qsSLkO \