Skip to content

Instantly share code, notes, and snippets.

@TurplePurtle
TurplePurtle / coolit.ts
Last active November 30, 2022 07:23
Iterable/Iterator utility library for TypeScript.
type MapToIterable<T> = { [K in keyof T]: Iterable<T[K]> };
type Tuple = readonly unknown[];
export function from<T>(it: Iterable<T>) {
return new DelegatingIterable<T>(it);
}
export function repeat<T>(value: T) {
return new RepeatIterable(value);
}
@TurplePurtle
TurplePurtle / zip-with.js
Created January 5, 2016 23:08
zipWith implementation
/*
* zipWith(...arrays, iteratee, [thisArg]) => array
*
* iteratee receives an element from each array as an argument
*/
function zipWith() {
// Argument count
var argc = arguments.length;
@TurplePurtle
TurplePurtle / phoenix-cheat-sheet.md
Last active December 21, 2015 21:12
Cheat sheet for starting a new Phoenix 1.1 project.
#include <stdio.h>
#include <string.h>
// serializing macros
#define serialize1(name, t1) void name(char* buffer, t1 a) { \
memcpy(buffer, &a, sizeof(t1)); }
#define serialize2(name, t1,t2) void name(char* buffer, t1 a, t2 b) { \
memcpy(buffer, &a, sizeof(t1)); \
memcpy(buffer + sizeof(t1), &b, sizeof(t1)); }
@TurplePurtle
TurplePurtle / gist:695be98a9fd6d2ac59ee
Created October 9, 2014 19:36
Arduino Balance Bot Code
/*
Coded by Santiago Jaramillo 2012
Connection setup:
=== ITG-3200 ===
VDD -> 3.3V
VIO -> 3.3V
GND -> GND
SDA -> A4
@TurplePurtle
TurplePurtle / classifier.rb
Created June 27, 2014 20:43
Bayes Classifier
require 'fast_stemmer'
require 'set'
class BayesClassifier
def initialize(categories)
raise "categories must be an Array" unless categories.is_a? Array
raise "At least 2 categories are needed" if categories.size < 2
@categories = categories.clone.freeze
@TurplePurtle
TurplePurtle / robot_frames.ino
Last active December 27, 2015 17:09
Robot keyframe movement.
#include <Servo.h>
// El numero de motores
static const unsigned int numServos = 2;
// Los motores, sus pins, y su posicion actual
static Servo servos[numServos];
static unsigned int servoPins[numServos] = {9,10};
static unsigned int servoPos[numServos] = {0};
@TurplePurtle
TurplePurtle / mathy.lua
Created October 17, 2013 02:57
Math expression evaluator and expression solver.
--------------------------------
-- StringBuffer (for printing out Trees)
--------------------------------
local stringBuffer
do
local function insert(buffer, item)
local len = buffer.length + 1
buffer.length = len
buffer[len] = item
end
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WebRTC p2p data</title>
<script src="https://webrtc-samples.googlecode.com/svn/trunk/apprtc/js/adapter.js"></script>
</head>
<body>
Testing WebRTC connection.
@TurplePurtle
TurplePurtle / sourceFromFile.js
Created October 27, 2012 21:36
Load sound from local file for Web Audio API
// Audio Buffer Source
var fileInput = $("#audio-file");
bufferSource.gain.value = 1;
bufferSource.loop = true;
bufferSource.connect(oscillatorGain);
fileInput.addEventListener("change", function() {
var reader = new FileReader();
reader.onload = function(ev) {
context.decodeAudioData(ev.target.result, function(buffer) {