Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Brevig AlexanderBrevig

View GitHub Profile
@AlexanderBrevig
AlexanderBrevig / gist:3811139
Created Oct 1, 2012
Batch convert .wav to .mp3 or .ogg
View gist:3811139
:: you must have oggenc or lame codecs installed and available in your PATH
cd path/to/your/folder/of/wav/files/to/convert
:: replace BITRATE with what you need, and use either of the following lines:
for /F %v IN ('dir /b *.wav') DO oggenc -m BITRATE %v
for /F %v IN ('dir /b *.wav') DO lame -b BITRATE %v
@AlexanderBrevig
AlexanderBrevig / gist:3811909
Created Oct 1, 2012
Make site contentEditable
View gist:3811909
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
@AlexanderBrevig
AlexanderBrevig / gist:4722354
Created Feb 6, 2013
Extension method for IList<T> for shuffling the content (not thread safe)
View gist:4722354
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class ListShuffle
{
public static void Shuffle<T>(this IList<T> list)
{
Random rand = new Random();
@AlexanderBrevig
AlexanderBrevig / str_append_from
Created Jul 8, 2013
avoid multiple traversals of strings that is implied by using strcat
View str_append_from
void str_append_from(char *original, int &idx, const char *append) {
while (*append) {
original[idx++] = *append++;
}
original[idx] = 0;
}
@AlexanderBrevig
AlexanderBrevig / gist:6086237
Created Jul 26, 2013
Small script for making audio in Unity3d sound as if they are played on the other side of a phone
View gist:6086237
using UnityEngine;
using System.Collections;
public class Mobilephonizer : MonoBehaviour
{
public AudioClip clip;
[RangeAttribute(0,20000)]
public int lowFrequencyCutoff = 1000;
@AlexanderBrevig
AlexanderBrevig / gist:6217627
Last active Dec 21, 2015
WProperty prototype
View gist:6217627
/*
||
|| @author Alexander Brevig <abrevig@wiring.org.co>
|| @url http://wiring.org.co/
|| @contribution Brett Hagman <bhagman@wiring.org.co>
|| @contribution Hernando Barragan <b@wiring.org.co>
||
|| @description
|| | A public field wrapper for providing assignment safe guards
|| #
View gist:6217634
class PropertyTester {
public:
PropertyTester()
: threshold()
, increment(PropertyTester::incrementAssignSafetyGuard)
, isIncrementing(_isIncrementing) {
_isIncrementing = true;
}
Property<int> threshold;
ConstrainedProperty<int> increment;
View Wiring vNEXT
/*
BEAT BLINKER
Simple demo of how to use two processing units
to implement a 'used to be' hard problem
*/
Microphone mic = Microphone(2, 8000); //pin 2 samplerate 8000 ?
Filter lowPass = LowPassFilter(100);
Threshold threshold = Threshold(50); //50%
LED beatBlinker = LED(WLED);
View ADFS 2.0 boilerplate
using Microsoft.IdentityModel.Protocols.WSTrust;
using Microsoft.IdentityModel.Protocols.WSTrust.Bindings;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.IdentityModel.Tokens;
string stsEndpoint = "https://YOURURL.com/adfs/services/trust/13/usernamemixed";
string relyingPartyUri = "https://attensi.com";
WSTrustChannelFactory factory = new WSTrustChannelFactory(
@AlexanderBrevig
AlexanderBrevig / Help for a nice guy
Last active Aug 29, 2015
Office project, light guiding to door
View Help for a nice guy
const int NUMBER_OF_ZONES = 19;
const int DOOR_OPEN_MS = 5 * 1000; // 5 seconds
const int ZONE_ON_MS = 10 * 60 * 1000; // 10 minutes
unsigned int zoneLastOn[NUMBER_OF_ZONES] = {};
void loop() {
//this is the multitasking part
//we just check the time that has passed since
//we last wanted it on and act accordingly