Skip to content

Instantly share code, notes, and snippets.

View ElectricCoffee's full-sized avatar

Niko Lepka ElectricCoffee

View GitHub Profile
// credit for this goes to makerofthings7 on stack exchange
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
#define CLOCK_PIN 2
#define LATCH_PIN 3
#define DATA_PIN 4
#define OPEN_LATCH digitalWrite(LATCH_PIN, 0)
#define CLOSE_LATCH digitalWrite(LATCH_PIN, 1)
byte digits[16];
void setup() {
pinMode(LATCH_PIN, OUTPUT);
@ElectricCoffee
ElectricCoffee / light_dependent_display.ino
Last active August 29, 2015 13:57
simple 2-digit display that shows the current light level in values ranging from 00 to FF
#define CLOCK_PIN 2
#define LATCH_PIN 3
#define DATA_PIN 4
#define READ_PIN 0
#define OPEN_LATCH digitalWrite(LATCH_PIN, 0)
#define CLOSE_LATCH digitalWrite(LATCH_PIN, 1)
byte digits[16];
void setup() {
@ElectricCoffee
ElectricCoffee / implicit_classes.scala
Last active August 29, 2015 13:58
a simple program that evaluates a string and returns a result
package com.wausoft.main
import scala.collection.mutable.Stack
trait ImplicitClasses {
implicit class RichStack[A](stack: Stack[A]) {
def operate(op: (A, A) => A): Unit = {
val (b, a) = (stack.pop, stack.pop)
stack push op(a,b)
}
@ElectricCoffee
ElectricCoffee / Collection Comparison.scala
Last active August 29, 2015 13:58
simple class enrichment for Seq, that allows you to perform boolean comparisons on them, these comparisons compare the sizes of the lists
// it's Seq[_] because we don't really care abou the type, all we're doing is comparing sizes anyway
implicit class RichSequence(a: Seq[_]) {
def ==(b: Seq[_]): Boolean = a.size == b.size
def !=(b: Seq[_]): Boolean = !(a == b)
def < (b: Seq[_]): Boolean = a.size < b.size
def <=(b: Seq[_]): Boolean = a < b || a == b
def > (b: Seq[_]): Boolean = !(a <= b)
def >=(b: Seq[_]): Boolean = !(a < b)
}
@ElectricCoffee
ElectricCoffee / while-else.scala
Last active August 29, 2015 13:58
the idea is to have a while-loop with an else statement
// what it tries to solve:
var cond = true
if(cond) {
while(cond) {
// do something
}
}
else {
// do something else
}
@ElectricCoffee
ElectricCoffee / Concept.txt
Last active August 29, 2015 14:00
A language concept that uses UML Class Diagram notation for the visibility and types, so + is public, - is private, # is protected, / is derived, _ is static, and ~ is a package. It's indentation based like Python and F#, and a block starts with a =. The only difference between a variable a class and a method, is that classes have members and me…
~ com.wausoft.test =
+ _ Program =
+ main(args: Array[String]): Unit = // unit is equivalent to void
printfn("this is a test")
- res = add(2, 4) // type inferred to int
printfn("result: $res") // example of string interpolation
+ add(a: Int, b: Int): Int = a + b
@ElectricCoffee
ElectricCoffee / stutter.txt
Last active August 29, 2015 14:00
An idea I had to make a lisp dialect, less focused on historical accuracy, and more focused on feeling like a modern language, and also having classes and objects be a central part of the language, rather than being "glued on" as it seems to be in some Lisp dialects
; Scala inspired Lisp
; I call it "Stutter" :3
; variable (mutable) definition:
(var a 5)
; value (immutable) definition:
(val b 4)
; function definition:
#!/bin/bash
function setup-sbt() {
# make the basic directories
mkdir -p "src/main/scala" # change scala to java if that's what you use
mkdir -p "src/main/resources"
mkdir -p "src/test/scala"
# make build file
touch build.sbt
@ElectricCoffee
ElectricCoffee / RichPath.scala
Last active August 29, 2015 14:03
A simple bit of extension methods that lets you write "someFolder" / "otherFolder" / "LastFolder" to create a java.io.File with that kind of path. An important feature of this, is that it's completely OS agnostic, meaning you don't have to worry about it being \ in Windows and / in Unix-based OSs, you just write it, and it handles the rest from …
import java.io.File
/**
* A completely OS-Agnostic way of dealing with java.io.File paths
*/
object RichPath {
sealed class RichBase[+A](left: A) {
/**
* Simple enrichment method designed to let you create a java.io.File
* by simply writing "folderA" / "folderB" / "folderC"