Skip to content

Instantly share code, notes, and snippets.

View AlexanderBrevig's full-sized avatar

Alexander Brevig AlexanderBrevig

View GitHub Profile
@AlexanderBrevig
AlexanderBrevig / BME280.js
Created April 10, 2015 10:50
Espruino BME280 module
var C = {
regCalibStart: 0x88,
regChipID: 0xd0,
regReset: 0xe0,
regCalibStart2: 0xe1,
regCtrlHum: 0xf2,
regStatus: 0xf3,
regCtrlMeas: 0xf4,
regConfig: 0xf5,
regMeasurementsStart: 0xf,
@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 {
{
"path": "C:/dev/Python27",
"cmd": ["python", "$file"],
"file_regex": "^[ ]*File \"(…*?)\", line ([0-9]*)",
"selector": "source.python"
}
/*
print "hello world"
*/
{
"path": "C:/Program Files (x86)/clisp-2.48/",
"cmd": ["clisp", "-i $file -x (main())"],
"selector": "source.lisp"
}
/*
(defun main (args)
(print "hello world")
(quit))*/
@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
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 / 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);
class PropertyTester {
public:
PropertyTester()
: threshold()
, increment(PropertyTester::incrementAssignSafetyGuard)
, isIncrementing(_isIncrementing) {
_isIncrementing = true;
}
Property<int> threshold;
ConstrainedProperty<int> increment;
@AlexanderBrevig
AlexanderBrevig / gist:6217627
Last active December 21, 2015 00:08
WProperty prototype
/*
||
|| @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
|| #
@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;