Skip to content

Instantly share code, notes, and snippets.

@brendandawes
brendandawes / Terminal:git:exportbranches
Last active December 6, 2017 11:41
Export branches. Replace <outputDirectory> with the path to where you want to export the branches.
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads);
do git archive --format zip --output <outputDirectory>/${branch}.zip $branch;
done
@brendandawes
brendandawes / index.html
Created August 23, 2016 11:28
p5.js: Fullscreen html and css
<html>
<head>
<script language="javascript" type="text/javascript" src="libraries/p5.js"></script>
<script type='text/javascript' src='libraries/p5.dom.js'></script>
<script type='text/javascript' src='libraries/sylvester.js'></script>
<style>
/* http://meyerweb.com/eric/tools/css/reset/
@brendandawes
brendandawes / ifttt-instagram-to-blog.php
Created July 28, 2016 08:22
IFTTT Make channel action to create blog post from new post on Instagram
<?php
/*
Action to create a blog post entry in my Kirby powered site via an IFTTT recipe. In IFTTT I have a an Instagram trigger that calls
this script, sending a POST using the Maake channel with this body: params={{EmbedCode}}&caption=<<<{{CaptionNoTag}}>>>
*/
if((isset($_POST['params']))){
$subject = urldecode($_POST['caption']);
@brendandawes
brendandawes / Particle.pde
Last active April 16, 2018 13:10
Processing:Particle Class
class Node {
private PVector vel;
private PVector loc;
private PVector acc;
Node () {
vel = PVector.random2D();
loc = new PVector(random(width), random(height));
@brendandawes
brendandawes / encodeURL.pde
Created June 11, 2016 14:37
URL encode text
String encodeURL(String s){
try {
String encoded = URLEncoder.encode(s, "UTF-8");
return encoded;
} catch (Exception e) {
return "ERROR";
}
}
@brendandawes
brendandawes / typeToImage.pde
Last active June 6, 2016 12:44
Processing:typeToImage
PGraphics typeToImage(String txt,PFont theFont, int fontSize){
PImage img;
ArrayList<PVector> vectors = new ArrayList();
PGraphics pg;
textFont(theFont);
textSize(fontSize);
textAlign(LEFT,TOP);
float w = textWidth(txt);
float h = fontSize;
pg = createGraphics(int(w),int(h),JAVA2D);
@brendandawes
brendandawes / minmaxTablerows.pde
Created June 5, 2016 13:22
Processing:Get Min Max Values from Table rows
int getMinValue(Table t, String colName){
int minValue = Integer.MAX_VALUE;
for (TableRow row: t.rows()) {
int val = row.getInt(colName);
if (val < minValue) minValue = val;
}
return minValue;
}
int getMaxValue(Table t, String colName){
@brendandawes
brendandawes / Processing:Comparator Example
Created June 2, 2016 10:39
Using a Comparator to sort arrays for classes
import java.util.Comparator;
import java.util.Collections;
Collections.sort(keywords, new CustomComparator());
public class CustomComparator implements Comparator<Keyword> {
@Override
public int compare(Keyword o1, Keyword o2) {
Integer val1 = (Integer) o1.keywordColor;
Integer val2 = (Integer) o2.keywordColor;
@brendandawes
brendandawes / alphaMaskToVectors.pde
Created June 1, 2016 13:44
Converts non-white pixels in a black & white image to an ArrayList of PVectors
ArrayList alphaMaskToVectors(String file){
PImage img = loadImage(file);
ArrayList vectors = new ArrayList();
for (int i=0; i < img.width; i++) {
for (int j=0; j < img.height; j++) {
color c = img.get(i,j);
if (red(c) != 255 && green(c) != 255 && blue(c) != 255) {
vectors.add(new PVector(i,j));
}
@brendandawes
brendandawes / Reasons.pde
Last active June 1, 2016 13:09
My little interpretation of the Reasons.to R
// Requires the DawesomeToolkit http://cloud.brendandawes.com/dawesometoolkit
import java.util.Collections;
import java.util.Random;
import dawesometoolkit.*;
import processing.pdf.*;
ArrayList<PVector> vectors;
DawesomeToolkit dawesome;