Skip to content

Instantly share code, notes, and snippets.

View ElectricCoffee's full-sized avatar

Niko Lepka ElectricCoffee

View GitHub Profile
@ElectricCoffee
ElectricCoffee / Repeat_After_Me.ino
Last active December 25, 2015 23:49
Simple program that uses the adafruit thermal printer to print out whatever messages you send it, currently it supports bold and underlined text, this sketch requires the Adafruit_Thermal library, which can be found here on GitHub, anything the program prints to serial is purely for debug purposes
#include <Adafruit_Thermal.h>
#include <SoftwareSerial.h>
#define PRINTER_RX 12
#define PRINTER_TX 13
#define SERIAL_BAUD 9600
Adafruit_Thermal printer(PRINTER_RX, PRINTER_TX);
boolean stringComplete = false;
@ElectricCoffee
ElectricCoffee / Obj-C Selectors.m
Created October 27, 2013 10:25
From one of my projects, I'm keeping this way of doing it for future reference, so I won't forget; the project currently uses function pointers instead; but this could come in handy.
double invokeCalculator(id object, SEL method, double price, double extraItemPrice, int index) {
double returnValue = 0xDEAD;
if([object respondsToSelector:method]) {
NSLog(@"object responded sucessfully");
NSInvocation* invocation =
[NSInvocation invocationWithMethodSignature: [object methodSignatureForSelector: method]];
[invocation setTarget: object]; // index 0
[invocation setSelector: method]; // index 1
[invocation setArgument: &price atIndex: 2]; // index 2
@ElectricCoffee
ElectricCoffee / dragon slayer.js
Last active December 29, 2015 23:09
based off of the codecademy dragon slayer tutorial program, but with loads of stuff added
var slaying = true;
var youHit = function() {
return Math.round(Math.random());
};
var damageThisRound = 0;
var damage = function(min, max) {
return Math.floor(Math.random() * max + min);
};
@ElectricCoffee
ElectricCoffee / ConsList.java
Created December 21, 2013 21:27
A Cons List in Java as an alternative to the ArrayList already found
public class ConsList<T extends Comparable<T>> {
private T _head;
private ConsList<T> _tail;
public ConsList(T head, ConsList<T> tail) {
_head = head;
_tail = tail;
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class ConsList<T> : IEnumerable where T : IComparable<T>
// 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 / attempts.scala
Created April 3, 2014 08:37
Basic method that lets you attempt to get a result up to a given number of times
def attempt[T,E <: Exception](attempts: Int, subject: String, failedMessage: String, exception: E, failCondition: T => Boolean)(body: => T): T = {
val i = body
if(failCondition(i) && attempts != 0) {
println(s"Subject: $subject")
println(s"Message: $failedMessage")
println(s"Attempts left: $attempts")
// do something with the exception
attempt(attempts - 1, subject, failedMessage, exception, failCondition)(body)
}
else i
@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)
}