Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Willson nbw

View GitHub Profile
View animals.txt
Canidae
Felidae
Cat
Cattle
Dog
Donkey
Goat
Guinea pig
Horse
Pig
@nbw
nbw / optionset_dictionary.swift
Last active Aug 29, 2018
Using an OptionSet with a Dictionary
View optionset_dictionary.swift
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 Aug 29, 2018
Hashable OpenSet
View hashable_openset.swift
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 Jul 30, 2018
threshold effect
View threshold.js
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 Jul 30, 2018
Pixelating a canvas image
View pixelation.js
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;
View draw.js
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 Jul 30, 2018
Drawing a video on canvas
View draw_video_on_canvas.js
//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 Jul 30, 2018
In-browser Webcam Video
View webcam.js
// Javascript
navigator.mediaDevices.getUserMedia({
video: {
width: ...,
height: ...,
frameRate: ...
}
}
).then(function(stream) {
let video = document.querySelector('video');
@nbw
nbw / .emacs
Created Apr 3, 2018
my emacs file
View .emacs
;; 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)
View gist:31f3873936a43fa297a7a682d9582a11
{
"you":
{
"taunt": "",
"object": "snake",
"name": "My snake",
"length": 3,
"id": "7433f0fe-cdb8-46e1-9b3b-a4a43d483579",
"health": 100,
"body": {
You can’t perform that action at this time.