Skip to content

Instantly share code, notes, and snippets.

View AlexanderBrevig's full-sized avatar

Alexander Brevig AlexanderBrevig

View GitHub Profile
@AlexanderBrevig
AlexanderBrevig / gist:3811139
Created October 1, 2012 11:44
Batch convert .wav to .mp3 or .ogg
:: 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 October 1, 2012 13:51
Make site contentEditable
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
@AlexanderBrevig
AlexanderBrevig / gist:4722354
Created February 6, 2013 12:55
Extension method for IList<T> for shuffling the content (not thread safe)
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 July 8, 2013 04:59
avoid multiple traversals of strings that is implied by using strcat
void str_append_from(char *original, int &idx, const char *append) {
while (*append) {
original[idx++] = *append++;
}
original[idx] = 0;
}
@AlexanderBrevig
AlexanderBrevig / gist:6086237
Created July 26, 2013 04:32
Small script for making audio in Unity3d sound as if they are played on the other side of a phone
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 December 21, 2015 00:08
WProperty prototype
/*
||
|| @author Alexander Brevig <[email protected]>
|| @url http://wiring.org.co/
|| @contribution Brett Hagman <[email protected]>
|| @contribution Hernando Barragan <[email protected]>
||
|| @description
|| | A public field wrapper for providing assignment safe guards
|| #
class PropertyTester {
public:
PropertyTester()
: threshold()
, increment(PropertyTester::incrementAssignSafetyGuard)
, isIncrementing(_isIncrementing) {
_isIncrementing = true;
}
Property<int> threshold;
ConstrainedProperty<int> increment;
@AlexanderBrevig
AlexanderBrevig / Wiring vNEXT
Created February 22, 2014 13:25
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);
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 August 29, 2015 14:04
Office project, light guiding to door
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