Skip to content

Instantly share code, notes, and snippets.

View AlexanderBrevig's full-sized avatar

Alexander Brevig AlexanderBrevig

View GitHub Profile
@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
{
"path": "C:/Program Files (x86)/clisp-2.48/",
"cmd": ["clisp", "-i $file -x (main())"],
"selector": "source.lisp"
}
/*
(defun main (args)
(print "hello world")
(quit))*/
{
"path": "C:/dev/Python27",
"cmd": ["python", "$file"],
"file_regex": "^[ ]*File \"(…*?)\", line ([0-9]*)",
"selector": "source.python"
}
/*
print "hello world"
*/
@AlexanderBrevig
AlexanderBrevig / gist:c529d3b7e08a3237ec05
Last active August 29, 2015 14:14
nancy before hook with setter
public interface IUserNancyModule { User CurrentUser { get; set; } }
public static class Hooks {
public static Func<NancyContext, Response> SetUserFromRequest(IUserNancyModule module, IAttensiContext db) {
return (ctx) => {
var usr = db.Users.FirstOrDefault(u=>u.EmployeeId == ctx.CurrentUser.UserName);
if (usr!=null) {
module.CurrentUser = usr;
return null; //let request pass
} else {
@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;
}