Skip to content

Instantly share code, notes, and snippets.

View a-r-d's full-sized avatar
🍌

Aaron Decker a-r-d

🍌
View GitHub Profile
@a-r-d
a-r-d / example.html
Created March 23, 2016 01:23
nanoforms content api system
<div class='additional-product-content'>
<div class='nano-content-api'
data-apiurl="https://forms.nanodolphin.com/api/content-api/find?apiKey=<KEY HERE>&key=cashew-berry">
</div>
</div>
<script>
jQuery(document).ready(function(){
jQuery.each(jQuery('.nano-content-api'), function(api) {
@a-r-d
a-r-d / dots-to-objects.js
Created March 21, 2016 01:55
Middleware to add dot notation body parser to express.
var _ = require('lodash');
module.exports = function(req, res, next) {
var parsed = {};
_.each(req.body, function(val, key) {
var splits, i, last, currentKey;
if(!!~key.indexOf('.')) {
splits = key.split('.');
last = parsed;
@a-r-d
a-r-d / chainable.html
Last active January 24, 2016 20:21
JavaScript Chainability experiment
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js'></script>
<script>
var mathy = function(init) {
return {
add: function add(x,y) {
return x + y;
},
mult: function mult(x,y) {
return x * y;
},
@a-r-d
a-r-d / functional-example.groovy
Created January 8, 2016 18:55
functional aspects of Groovy using closures (in Groovy parlance)
// map, reduce, filter
l = [1,2,3,4]
l.collect { it + 1 }
//--> [2,3,4,5]
l.inject { l, n -> l + n }
//--> 10
l.findAll { it % 2 == 0 }
@a-r-d
a-r-d / convert-and-split.sh
Last active August 2, 2023 20:46
How to take an annoying APE + CUE file cd rip and convert it into a set of FLAC or MP3 files on ubuntu.
#first install all the things:
sudo apt-get install flac ffmpeg mp3splt libav-tools shntool
# Okay first lets do an MP3:
# input files:
# --> cd.ape
# --> cp.cue
# (there are other options, like bitrate, but this is just the bare bones)
avconv -i cd.ape cd.mp3
@a-r-d
a-r-d / class-composition.js
Created January 7, 2016 20:57
An example of what happens when you try to compose a class in javascript. Sometimes the context is not what it seems.
function RequiredComponent() {
this.setValA = (val) => {
// this will stay on the component
this.a = val;
}
}
RequiredComponent.prototype.setValB = function(val) {
// this will actually modify the container if you set the value to the method.
@a-r-d
a-r-d / weather.py
Last active January 7, 2016 03:18
Python script to send weather API data to an LCD on arduino.
import time
import math
import urllib2
import json
import traceback
ser = None
MOUNT = "/dev/ttyACM0" #raspi
#MOUNT = "COM3" #windows
ENDPOINT = "http://api.wunderground.com/api/< API KEY >/forecast10day/q/OH/Cincinnati.json"
@a-r-d
a-r-d / const-container.js
Created January 6, 2016 19:55
A system for creating a global constant container with read only props.
const ConstContainer = {
add: (k,v) => {
if(ConstContainer.hasOwnProperty(k)) return false;
Object.defineProperty(ConstContainer, k, {value: v});
},
// format as array of arrays: [['key', 'value'], ['key', 'value']]
addMany: (arr) => {
arr.forEach((iter) => {
ConstContainer.add(iter[0], iter[1]);
});
@a-r-d
a-r-d / wrap-console.js
Created January 6, 2016 19:52
An example of how to wrap the console.log method with a prefix to the message.
function wrap(object, method, wrapper) {
var fn = object[method];
return object[method] = function() {
return wrapper.apply(this, [fn.bind(this)].concat(
Array.prototype.slice.call(arguments)));
};
}
wrap(console, 'log', function(original) {
var args = Array.prototype.slice.call(arguments);
@a-r-d
a-r-d / dedupe-array-of-objects.js
Created December 8, 2015 15:21
Deduplicate an array of objects in javascript
function deDupeArrayOfObjects(arr) {
var tmpMap = {};
arr.forEach(function(val) {
var uniquekey = '';
for(var k in val) {
if(val.hasOwnProperty(k) && val[k]) {
uniquekey += val[k].toString();
}
}
tmpMap[uniquekey] = val;