Skip to content

Instantly share code, notes, and snippets.

@animat
animat / gist:a09ad104e5c432217726
Created July 4, 2015 15:16
AngularJS retain scroll position (attempt)
.directive("keepScrollPos", function($route, $window, $timeout, $location, $anchorScroll) {
// cache scroll position of each route's templateUrl
var scrollPosCache = {};
// compile function
return function(scope, element, attrs) {
scope.$on('$routeChangeStart', function() {
// store scroll position for the current view
if ($route.current) {
@animat
animat / gist:043cc173e8474b489af8
Created May 19, 2015 14:15
Reading data from .csv files in Processing
// First, the .csv file needs to be saved in a place where the project will be able to access it:
// Create a folder called "data" and place it in the project's folder.
// The .csv file should be placed inside of that "data" folder.
void setup() {
Table data;
// Load in the .csv file. Note that the first row of this file names each of the columns (AKA a header row)
data = loadTable("absences.csv", "header");
// Use a while loop to iterate through all of the rows...
@animat
animat / gist:231603d3d8aaf3ae2355
Created May 14, 2015 15:57
Mirror image scaffolding
void setup() {
size(179*2, 179);
// Load the original image
PImage pic = loadImage("http://cdn.theatlantic.com/static/mt/assets/business/smiley%20face%20wikimedia.png");
// Draw the original image at 0, 0
image(pic, 0, 0);
// Iterate through all of the pixels on the left half of the window
int yCoord = 0;
while(yCoord < height){
// The following gist assumes that you have a data folder with a file called helloWorld.noah in it
String[] lines;
void setup() {
lines = loadStrings("helloWorld.noah");
size(500, 500);
for (String line : lines) {
String[] tokens = line.split(" ");
println(line);
}
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK (2)
#define PN532_MOSI (3)
#define PN532_SS (4)
#define PN532_MISO (5)
@animat
animat / ParticleClass
Created April 16, 2015 12:50
ParticleSimulator
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
PVector gravity;
Particle() {
location = new PVector(width/2, 0);
velocity = new PVector(0, 0);
acceleration = new PVector(random(-.3, .3), 0);
class Particle {
PVector location;
PVector velocity;
PVector acceleration;
PVector gravity;
Particle() {
location = new PVector(width/2, 0);
velocity = new PVector(0, 0);
acceleration = new PVector(random(-.3, .3), 0);
#include <Adafruit_NeoPixel.h>
#define PIN 6
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
void setup() {
size(500, 500);
}
void draw() {
background(255);
drawStar(mouseX, mouseY);
}
// Draw a star
// (How? Up to you. I'd recommend a * shape with five lines originating from the center)