Skip to content

Instantly share code, notes, and snippets.

Canidae
Felidae
Cat
Cattle
Dog
Donkey
Goat
Guinea pig
Horse
Pig
@nbw
nbw / optionset_dictionary.swift
Last active August 29, 2018 18:26
Using an OptionSet with a Dictionary
let DictionaryLookUp : [OptionSetHash: Bool] = [
.first: true,
.second: false,
.third: true
]
// Example: cycling through options in a dictionary
var options = OptionSetHash.init(rawValue: 0)
for (key, value) in DictionaryLookUp {
@nbw
nbw / hashable_openset.swift
Last active August 29, 2018 17:08
Hashable OpenSet
struct OptionSetHash: OptionSet, Hashable {
let rawValue: Int
var hashValue: Int {
return self.rawValue
}
static let first = OptionSetHash(rawValue: 1 << 0)
static let second = OptionSetHash(rawValue: 1 << 1)
static let third = OptionSetHash(rawValue: 1 << 2)
@nbw
nbw / threshold.js
Created July 30, 2018 23:21
threshold effect
function(context, threshold, width, height) {
let image, data, r, g, b, color;
image = context.getImageData(0, 0, width, height);
data = image.data;
for (let i = 0; i< data.length; i = i+4) {
r = data[i];
g = data[i+1];
@nbw
nbw / pixelation.js
Created July 30, 2018 23:19
Pixelating a canvas image
function.pixelate(image, canvas, context, pixelSize) {
let wScaled, hScaled, scale;
scale = 1/pixelSize;
wScaled = canvas.width*scale;
hScaled = canvas.height*scale;
context.drawImage(image, 0, 0, wScaled, hScaled);
context.mozImageSmoothingEnabled = false;
context.imageSmoothingEnabled = false;
function draw(video, canvas, context, frameRate) {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
setTimeout(draw, 1/frameRate, video, canvas, context, frameRate);
}
@nbw
nbw / draw_video_on_canvas.js
Created July 30, 2018 23:14
Drawing a video on canvas
//javascript
var canvas = document.querySelector('canvas');
canvas.width = ...;
canvas.height = ...;
var context = canvas.getContext('2d');
context.drawImage(video, 0, 0, canvas.width, canvas.height);
// video 'play' event listener
@nbw
nbw / webcam.js
Created July 30, 2018 23:11
In-browser Webcam Video
// Javascript
navigator.mediaDevices.getUserMedia({
video: {
width: ...,
height: ...,
frameRate: ...
}
}
).then(function(stream) {
let video = document.querySelector('video');
@nbw
nbw / .emacs
Created April 3, 2018 15:17
my emacs file
;; MELPA
(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
(setq package-enable-at-startup nil)
(package-initialize)
{
"you":
{
"taunt": "",
"object": "snake",
"name": "My snake",
"length": 3,
"id": "7433f0fe-cdb8-46e1-9b3b-a4a43d483579",
"health": 100,
"body": {