Skip to content

Instantly share code, notes, and snippets.

View ofZach's full-sized avatar

ofZach

View GitHub Profile
@ofZach
ofZach / gist:8816529
Last active August 29, 2015 13:56
ruby to make markdown links a href target blank links. sort of doesn't work with link URLs that have () in them -- like some wikipedia urls that disambiguate. also seems to convert images inadvertently as well as markdown links since they have a similar-ish format.
File.open('test.txt', 'r+') do |f|
out = ""
f.each do |line|
out << line.gsub(/\[([^\]]+)\]\(([^)]+)\)/, '<a target="_blank" href="\2">\1</a>')
end
f.pos = 0
f.print out
f.truncate(f.pos)
end
@ofZach
ofZach / gist:9691433
Created March 21, 2014 17:34
small snippet for using DSP filters collection...
// usage for DSP
// https://github.com/vinniefalco/DSPFilters
#include "Dsp.h"
// variables... these filters want a float ** array, so I allocate it like this:
Dsp::Filter* f;
float* audioData[1];
@ofZach
ofZach / gist:9905458
Created April 1, 2014 00:37
rename testApp to ofApp
# rename files:
find . -type f -iname "testApp.h" -exec rename 's/testApp/ofApp/' {} \;
find . -type f -iname "testApp.cpp" -exec rename 's/testApp/ofApp/' {} \;
#find and replace
find . -type f -iname "ofApp.h" -exec sed -i "" 's/testApp/ofApp/g' {} \;
find . -type f -iname "ofApp.cpp" -exec sed -i "" 's/testApp/ofApp/g' {} \;
for hiro
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(255,0,127);
ofBeginShape();
@ofZach
ofZach / gist:f64f27f03cd0e57b4434
Created October 3, 2014 18:35
supercollider examples
// some small examples from in-class
f = { 1 + 1 + 1};
f.value;
a = {SinOsc.ar(440)}.play
a.free
@ofZach
ofZach / gist:5c122f3ad33b47cd068a
Created December 1, 2014 23:03
trying to figure out setupOffAxisViewPortal
// make a sphere
ofSpherePrimitive sph;
sph.set(100, 10);
ofMesh s = sph.getMesh();
// grab the current camera
// this is to figure out where a camera "should" be, ie, for this overall picture where is the camera.
ofCamera mainCam;
mainCam.setupPerspective();
@ofZach
ofZach / statistics
Created November 4, 2012 22:23
statistics / C++
/// This is a recipe from the O'Reilly Safari Cookbook
/// http://safari.oreilly.com/0596007612/cplusplusckbk-CHP-11-SECT-5
/// Usage:
/// vector<int> v;
/// computeStats(v.begin( ), v.end( ), sum, mean, var, dev, skew, kurt);
#pragma once
// was noticing sin(ofGetElapsedTimef()) gets crunchy at some point, because of lower resolution in sin / cos. here's an alternative function that seems to help... not tested for speed.
float ofGetElapsedTimeForSin(){
long long timeNow = ofGetElapsedTimeMillis();
long long modForTwoPi = (int)(TWO_PI*1000.0);
return ((float)(timeNow % modeForTwoPi)/1000.0);
}
@ofZach
ofZach / gist:7808368
Created December 5, 2013 16:20
modifying glfw window in OF (0.8)
// in main.cpp
ofAppGLFWWindow w;
ofSetupOpenGL(&w, 1024,432,OF_WINDOW); // <-------- setup the GL context
testApp * app = new testApp();
app->WINDOW = &w;
ofRunApp(app);
@ofZach
ofZach / gist:8255060
Created January 4, 2014 12:44
funky curved line via ofNode
// in .h file:
ofNode a,b,c;
float aEnergy;
float bEnergy;
float aEnergySmth;
float bEnergySmth;
float time;
ofPolyline nodeLine;