Skip to content

Instantly share code, notes, and snippets.

@sidmani
sidmani / tabun_user.json
Last active June 27, 2018 04:09
Tabun user settings
{
"decks": []
}
@sidmani
sidmani / parse_posts.js
Created May 9, 2018 21:11
automatic post index generation for blogs
'use strict';
// parse markdown files to html
const fs = require('fs');
const postTemplate = fs.readFileSync('templates/post.t', 'utf8');
const postIndexTemplate = fs.readFileSync('templates/post_index.t', 'utf8');
function parsePost(text) {
let post = {};
let match = /([\w\W]+?) <([\W\w]*?)>\n\/\/ ([\W\w]*?)\n([\W\w]*)/g.exec(text);
post.title = match[1];
@sidmani
sidmani / unit_test.js
Last active February 4, 2018 22:47
Minimalist Node.js unit testing script
// Copyright (c) 2018 Sid Mani
// https://sidmani.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
@sidmani
sidmani / midi_keyboard.ino
Created January 9, 2018 00:25
MIDI keyboard with Teensyduino
/*
* MIT License
* Copyright (c) 2018 Sid Mani
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
@sidmani
sidmani / beatreader.ino
Last active January 8, 2018 04:00
Simple method to flash an RGB LED to audio input.
/*
* MIT License
* Copyright (c) 2018 Sid Mani
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@sidmani
sidmani / multicomparison.swift
Created October 4, 2017 23:57
Chaining comparison operators in Swift
infix operator <: AdditionPrecedence
infix operator >: AdditionPrecedence
infix operator <=: AdditionPrecedence
infix operator >=: AdditionPrecedence
class AccumulatedComparison<T: Comparable> {
var result: Bool
var value: T
init(result: Bool, value: T) {
@sidmani
sidmani / gist:b7064986044d2bf3f33104b8b63f8122
Created September 5, 2017 00:13
UIBezierPath, functional programming style
class Path {
private let path: UIBezierPath
init() { self.path = UIBezierPath() }
func move(to point: CGPoint) -> Path {
path.move(to: point)
return self
}
func addArc(withCenter center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) -> Path {
@sidmani
sidmani / DictionaryEncoder.swift
Last active May 10, 2023 11:32
quick protocol for creating dictionaries from types
// simple alternative to using swift 4's encodable protocol when you just need to quickly create a dictionary
// usage:
// struct SomeData: DictionaryEncodable {
// enum Key: String {
// case someValue
// }
//
// let someValue = 5
//
// func encode(_ encoder: DictionaryEncoder) {
/// custom unique identifier
/// @see https://www.firebase.com/blog/2015-02-11-firebase-unique-identifiers.html
private let ASC_CHARS = Array("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz")
private let DESC_CHARS = ASC_CHARS.reverse()
private var lastPushTime: UInt64 = 0
private var lastRandChars = Array<Int>(count: 12, repeatedValue: 0)
func generatePushID(ascending: Bool = true) -> String {
let PUSH_CHARS = ascending ? ASC_CHARS: DESC_CHARS
var timeStampChars = Array<Character>(count: 8, repeatedValue: PUSH_CHARS.first!)