Skip to content

Instantly share code, notes, and snippets.

View jeffremer's full-sized avatar

Jeff Remer jeffremer

View GitHub Profile
// List of 3D coordinates
const vertices = [
[-0.5, 0, -0.5],
[0.5, 0, -0.5],
...
];
// A utility that projects 3D points to 2D screen-space
// Using a virtual 'camera' that has a 3D position and target
// And viewport width and height
@mattdesl
mattdesl / sketch.js
Last active April 29, 2022 07:10
h264-mp4-encoder + canvas-sketch = in-browser MP4 generation
// npm canvas-sketch-cli -g
// canvas-sketch sketch.js --open
const canvasSketch = require('canvas-sketch');
const H264 = require('h264-mp4-encoder');
const { lerp } = require("canvas-sketch-util/math");
const settings = {
duration: 4,
dimensions: [1024, 1024],
@mattdesl
mattdesl / about.md
Last active December 15, 2023 17:45
png + svg export with canvas-sketch and context 2D

PNG + SVG export from canvas-sketch

The helper function canvas-to-svg.js wraps a given render function (or renderer object) so that you can use Canvas2D context methods as usual, but upon single frame export (with Cmd/Ctrl + S) it will produce both a PNG and SVG file.

This uses canvas2svg which is not a perfect solution, as the Canvas2D API was never designed to be translated to SVG. Its best to stick with simple shape and path operations.

Full instructions: first install the canvas-sketch CLI if you haven't already:

npm install canvas-sketch-cli -g
@mattdesl
mattdesl / audio-example.js
Last active September 29, 2023 20:08
canvas-sketch + audio example https://microphone-circle.surge.sh/
const canvasSketch = require('canvas-sketch');
// A handy module to compute the average signal between two frequencies
// https://www.npmjs.com/package/analyser-frequency-average
const frequencyAverage = require('analyser-frequency-average');
const settings = {
// Animate the sketch
animate: true
};
@nielsbot
nielsbot / gist:4669657
Last active December 11, 2015 22:28
Tired of dealing with NSNull in your KVO observers? I use this.
@implementation NSNull (IfNullThenNil)
-(id)ifNullThenNil { return nil ; }
@end
@implementation NSObject (IfNullThenNil)
-(id)ifNullThenNil { return self ; }
@end
@subdigital
subdigital / pns.m
Created January 5, 2013 21:59
What are your favorite Xcode Snippets? Add them in the comments.
// Property Nonatomic Strong
// Platform: All
// Completion Scopes: ClassInterfaceMethods
@property (nonatomic, strong) <# class_name #> *<# variable_name #>;
@rhysforyou
rhysforyou / gist:4417106
Last active December 10, 2015 09:49 — forked from statico/gist:3172711
A step-by-step guide on using a PS3 controller with OS X

How to use a PS3 controller on Mac OS X 10.8 (Mountain Lion)

  1. Open Apple menu → System Preferences → Bluetooth and disable Bluetooth on Mac as well as any other nearby Macs or devices which will try to pair with and confuse the controller.

  2. Reset PS3 controller by inserting paperclip into pinhole near L2 button.

  3. Connect PS3 controller to Mac with USB cable.

  4. Enable Bluetooth.

@mmdumi
mmdumi / EncodePolyline
Created November 2, 2012 09:09
Encode polyline. Google Maps API v3 algorithm. Objective c.
+ (NSString *)encodeStringWithCoordinates:(NSArray *)coordinates
{
NSMutableString *encodedString = [NSMutableString string];
int val = 0;
int value = 0;
CLLocationCoordinate2D prevCoordinate = CLLocationCoordinate2DMake(0, 0);
for (NSValue *coordinateValue in coordinates) {
CLLocationCoordinate2D coordinate = [coordinateValue MKCoordinateValue];
@sxua
sxua / 0-readme.md
Created October 13, 2012 16:14 — forked from burke/0-readme.md
ruby-1.9.3-p286 cumulative performance patch.

Patch for ruby 1.9.3-p327 is here: https://gist.github.com/4063779

Patched ruby 1.9.3-p286 for 30% faster rails boot

Overview

This script installs a patched version of ruby 1.9.3-p286 with boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Many thanks to funny-falcon for the performance patches.

@equivalent
equivalent / README.md
Last active December 16, 2021 16:34
String "false" to_bool ... or how to convert Rails/SimpleForm radio buttons to boolean

This gist was writen in 2012 and it was solving specific problem in Rails & SimpleForm. Some fellow developers were pointing out this may be out dated concept. That's why I advise everyone to read comment section bellow to have a full grasp of alternative solutions

other sources that may be helpful to understand why this may not be best idea: