Skip to content

Instantly share code, notes, and snippets.

@danellis
danellis / Test.gs
Created December 13, 2017 06:24
Demo music
{
"id": "15815873-e1cf-49bb-a57e-b3cbf3cab4d6",
"bpm": 120,
"stepsPerBeat": 4,
"beatsPerMeasure": 4,
"name": "Test",
"duration": 48,
"patterns": {
"i1": { "name": "Bass", "type": "keys", "keys": "i2", "synth": "i0", "duration": 4 },
"i2b": { "name": "Chords", "type": "keys", "keys": "i2a", "synth": "i28", "duration": 8 },
@danellis
danellis / aoc2017d4.scala
Created December 4, 2017 09:20
AoC 2017 | day 4 | parts 1 & 2
val input = "..."
val phrases = input.lines.toList.map(_.split("\\s").toList)
def passesCheck1(words: List[String]): Boolean = {
Set(words: _*).size == words.length
}
def passesCheck2(words: List[String]): Boolean = {
val anagrams = words.flatMap(w => w.permutations.toSet - w)
@danellis
danellis / bitwisemod.scala
Created December 4, 2017 08:26
Bitwise modulus
def bitwiseIsDivisible(pair: Array[Int]): Boolean = {
var (numerator, denominator) =
if (pair(0) >= pair(1)) (pair(0), pair(1))
else (pair(1), pair(0))
var remainder = numerator
var quotient = 0
while (remainder >= denominator) {
remainder = sub(remainder, denominator)
quotient = add(quotient, 1)
@danellis
danellis / aoc2017d3p2.scala
Created December 3, 2017 09:43
AoC 2017 | day 3 | part 2
import scala.annotation.tailrec
val input = 347991
type Grid = Map[(Int, Int), Int]
val grid: Grid = Map(
(0, 0) -> 1,
(1, 0) -> 1
).withDefaultValue(0)
@danellis
danellis / aoc2017d3p1.scala
Last active December 3, 2017 09:43
AoC 2017 | day 3 | part 1
import math._
val input = 347991
def distance(n: Int) = {
val level = ((sqrt(n) - 1) / 2).ceil.toInt
val br = pow(level * 2 + 1, 2).toInt
val offset = br - n
val length = level * 2 + 1
val k = length - 1
@danellis
danellis / ignite.log
Created November 29, 2017 18:35
Ignite cluster activation failure
13:33:06.524 INFO o.a.ignite.internal.IgniteKernal -
>>> __________ ________________
>>> / _/ ___/ |/ / _/_ __/ __/
>>> _/ // (7 7 // / / / / _/
>>> /___/\___/_/|_/___/ /_/ /___/
>>>
>>> ver. 2.2.0#20170915-sha1:5747ce6b
>>> 2017 Copyright(C) Apache Software Foundation
>>>
@ val sources = List(Source(1 :: 2 :: 3 :: Nil), Source(4 :: 5 :: 6 :: Nil), Source(7 :: 8 :: 9 :: Nil))
sources: List[Source[Int, akka.NotUsed]] = List(
Source(SourceShape(StatefulMapConcat.out(666586581))),
Source(SourceShape(StatefulMapConcat.out(1638756960))),
Source(SourceShape(StatefulMapConcat.out(136416115)))
)
@ val futures = sources.map(_.runWith(Sink.seq))
futures: List[concurrent.Future[collection.immutable.Seq[Int]]] = List(
Future(Success(Vector(1, 2, 3))),
@danellis
danellis / struct_init.c
Created February 18, 2016 07:09
C anonymous inner struct initialization
#include <stdio.h>
typedef struct {
// Required
const char *fq_name[3];
// Optional
const char *display_name;
const char *href;
const char *name;
val myRoute =
pathPrefix("rest") {
controller("apps", RestController(AppDao)) ~
controller("clusters", RestController(ClusterDao)) ~
controller("commits", RestController(CommitDao)) ~
controller("deployments", RestController(DeploymentDao)) ~
controller("config-keys", RestController(ConfigKeyDao)) ~
controller("config-values", RestController(ConfigValueDao)) ~
controller("blades", RestController(BladeDao)) ~
controller("stacks", RestController(StackDao)) ~
class Parent[T <: Parent[_]] {
def foo = this.asInstanceOf[T]
}
class Child extends Parent[Child]