Skip to content

Instantly share code, notes, and snippets.

@justjoheinz
justjoheinz / Configuration.h
Created November 26, 2011 13:45
Marlin Config
#ifndef __CONFIGURATION_H
#define __CONFIGURATION_H
// This determines the communication speed of the printer
//#define BAUDRATE 250000
#define BAUDRATE 115200
//#define BAUDRATE 230400
@justjoheinz
justjoheinz / excerpt.cpp
Created November 27, 2011 11:55
switch statement for ISR in Marlin firmware
switch(temp_state) {
case 0: // Prepare TEMP_0
#ifdef NORMAL_OP
#if (TEMP_0_PIN > -1)
#if TEMP_0_PIN > 7
ADCSRB = 1<<MUX5;
#endif
ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
ADCSRA |= 1<<ADSC; // Start conversion
#endif
@justjoheinz
justjoheinz / Makefile
Created March 17, 2012 13:41
Super simple beagleboneio project
INCLUDE_PATH=/opt/local/include
LIBRARY_PATH=/opt/local/lib
CC_OPTS=-O2
all:
gcc test.c -o test $(CC_OPTS) -I$(INCLUDE_PATH) -L$(LIBRARY_PATH) -lbeagleboneio
package scalaio
import shapeless._, poly._
object list extends (Id ~> List) {
def apply[T](t : T) = List(t)
}
object headOption extends (List ~> Option) {
def apply[T](l : List[T]) = l.headOption
@justjoheinz
justjoheinz / Application.scala
Created November 15, 2013 08:32
Gist to describe problems testing actors which are instantiated in a Play2 controller.
package controllers
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits._
import play.api.Play.current
import play.api.libs.concurrent.Akka
import play.api.mvc._
import akka.actor._
@justjoheinz
justjoheinz / gist:7613775
Created November 23, 2013 11:55
Chaining Validations
class ChainedValidation[E,A](val x : A, val validationResult: ValidationNel[E,A]) {
def andThen(f: A => ValidationNel[E, A])(implicit s1: Semigroup[E]) : ChainedValidation[E,A] = {
// calculate new validation
val newResult = f(x)
validationResult match {
// (success & newResult) =>
case Success(_) =>
newResult match {
/**
* Original source:
* [[https://gist.github.com/oxbowlakes/970717]]
*
* Modifications:
* - use scala 7.0.5
* - use toValidationNel
* - use sequenceU and traverseU instead of the lambda trick
*
* Part Zero : 10:15 Saturday Night
@justjoheinz
justjoheinz / gist:9217194
Created February 25, 2014 20:38
Functor / implicit conversion
package functional
trait Functor[F[_]] {
def fmap[A, B](fa: F[A])(f: A => B): F[B]
}
final class FunctorOps[F[_], A](val self: F[A])(implicit val F: Functor[F]) {
final def fmap[B](f: A => B) = F.fmap(self)(f)
}
@justjoheinz
justjoheinz / NaturalTransformation.scala
Created October 10, 2014 15:39
Attempt to get the coproduct of natural transformations working.
trait NaturalTransformation[-F[_], +G[_]] {
self =>
def apply[A](fa: F[A]): G[A]
def compose[E[_]](f: E ~> F): E ~> G = new (E ~> G) {
def apply[A](ea: E[A]) = self(f(ea))
}
def or[H[_]](f: H ~> G): ({type f[x] = Coproduct[F, H, x]})#f ~> G =
new (({type f[x] = Coproduct[F, H, x]})#f ~> G) {
@justjoheinz
justjoheinz / test.scala
Created February 3, 2015 21:56
Dependent Values
package optionStuff
import scalaz._
import Scalaz._
object optionStuff extends App {
case class Test(a: Option[String], b: Option[String])
case object Error
implicit val errorInstance = new Monoid[Error.type] {