Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Tiemen Waterreus Tmw

🚀
View GitHub Profile
View google-challange-atm-queue.rs
struct Case<'a> {
title: &'a str,
max_amount: usize,
wanted_amounts: Vec<usize>,
}
fn main() {
// Setup the various cases
let simulations = vec![
@Tmw
Tmw / Huffman.ex
Created Sep 2, 2020
Huffman encoder / decoder from scratch using Elixir
View Huffman.ex
defmodule Huffman do
defmodule Node do
defstruct [:left, :right]
end
defmodule Leaf do
defstruct [:value]
end
def encode(text \\ "cheesecake") do
@Tmw
Tmw / cube_v1.ino
Created Feb 1, 2016
Source for Cube V1
View cube_v1.ino
#include <SPI.h>
// define pins and other variables
const int latchPin = 8;
const int clockPin = 13;
const int dataPin = 11;
const int NUMBER_OF_CONNECTED_LEDS = 16;
// global array that keeps track of the LEDs brightnesses
bool brightnessMask_layer1[NUMBER_OF_CONNECTED_LEDS*4];
@Tmw
Tmw / refresh.ino
Last active Feb 1, 2016
The expanded refresh function
View refresh.ino
void refresh(){
// Loop over each LED
for (int cycle = 0; cycle < 16; cycle++) {
for (int currentLed = 0; currentLed < NUMBER_OF_CONNECTED_LEDS; currentLed++) {
int maskPosition = currentLed * 4;
if (cycle == 1 && brightnessMask_layer1[maskPosition]) {
turnOnLed(currentLed, 0);
}
@Tmw
Tmw / write_to_brightnessmask.ino
Last active Feb 1, 2016
Writing values to the brightnessMask array
View write_to_brightnessmask.ino
void led(int x, int y, int z, int brightness){
// ensure 4-bit limited brightness
brightness = constrain(brightness, 0, 15);
int ledNr = y*4+x;
// turn 4-bit brightness into brightness mask
for (int i = 3; i >= 0; i--) {
if (brightness - (1 << i) >= 0) {
brightness -= (1 << i);
@Tmw
Tmw / brightnessMasks.ino
Last active Feb 1, 2016
expanding our brightnessMask array
View brightnessMasks.ino
bool brightnessMask_layer1[NUMBER_OF_CONNECTED_LEDS*4];
bool brightnessMask_layer2[NUMBER_OF_CONNECTED_LEDS*4];
bool brightnessMask_layer3[NUMBER_OF_CONNECTED_LEDS*4];
bool brightnessMask_layer4[NUMBER_OF_CONNECTED_LEDS*4];
@Tmw
Tmw / turnOnLed.ino
Last active Feb 1, 2016
expanding our turnOnLed function
View turnOnLed.ino
// turn on correct LED using 595's
void turnOnLed(int ledNr, int layer) {
digitalWrite(latchPin, LOW);
SPI.transfer(1<<layer);
if (ledNr >= 8) {
SPI.transfer(1<<ledNr-8);
SPI.transfer(0);
}
else {
@Tmw
Tmw / gist:fa18019595a36e3f190a
Last active Aug 29, 2015
Combining multiple Active_Model_Serializers in one output
View gist:fa18019595a36e3f190a
class PersonSerializer < ActiveModel::Serializer
attributes :first_name, :last_name
def attributes
super.merge(AddressSerializer.new(object.address).serializable_hash)
end
end
# Given a model Person with an association has_one Address
# The example above will serialize to:
# {
@Tmw
Tmw / BAM.ino
Created May 9, 2015
Bit Angle Modulation, Arduino and Shift Registers
View BAM.ino
#include <SPI.h>
// define pins and other variables
const int latchPin = 8;
const int clockPin = 13;
const int dataPin = 11;
const int NUMBER_OF_CONNECTED_LEDS = 16;
// global array that keeps track of the LEDs brightnesses
bool brightnessMask[NUMBER_OF_CONNECTED_LEDS*4];
@Tmw
Tmw / BAM.ino
Last active Aug 29, 2015
Basic Bit Angle Modulation using Arduino and 595 shift registers
View BAM.ino
#include <SPI.h>
// define pins and other variables
const int latchPin = 8;
const int clockPin = 13;
const int dataPin = 11;
const int NUMBER_OF_CONNECTED_LEDS = 16;
// global array that keeps track of the LEDs brightnesses
bool brightnessMask[NUMBER_OF_CONNECTED_LEDS*4];
You can’t perform that action at this time.