Skip to content

Instantly share code, notes, and snippets.

Avatar

Gareth gahrae

  • Boulder, CO, USA
View GitHub Profile
@gahrae
gahrae / silent-night-omega2.py
Created Jul 25, 2020 — forked from root42/silent-night-omega2.py
Plays "silent night" on a piezo buzzer attached to pin 18 of the Onion Omega2
View silent-night-omega2.py
#!/usr/bin/env python
# Plays "silent night" on a piezo buzzer attached to pin 18 of the Onion Omega2
# Things required: python lite, pwm needs to be enabled via:
# omega2-ctrl gpiomux set pwm0 pwm
from time import sleep
exportStr="/sys/class/pwm/pwmchip0/export"
periodStr="/sys/class/pwm/pwmchip0/pwm%s/period"
dutyStr="/sys/class/pwm/pwmchip0/pwm%s/duty_cycle"
@gahrae
gahrae / Example.java
Last active Aug 4, 2018
Demonstrate using EasyMock to mock a method argument modification.
View Example.java
import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.junit.Assert;
import org.junit.Test;
/*
* Demonstrate using EasyMock to mock a method argument modification.
*/
// Dependency to mock...
@gahrae
gahrae / decodeFloat.js
Created Dec 18, 2015 — forked from kg/decodeFloat.js
Decode 32/64-bit float from bytes in JavaScript
View decodeFloat.js
// Derived from http://stackoverflow.com/a/8545403/106786
function decodeFloat(bytes, signBits, exponentBits, fractionBits, eMin, eMax, littleEndian) {
var totalBits = (signBits + exponentBits + fractionBits);
var binary = "";
for (var i = 0, l = bytes.length; i < l; i++) {
var bits = bytes[i].toString(2);
while (bits.length < 8)
bits = "0" + bits;
@gahrae
gahrae / Int64.js
Created Dec 17, 2015 — forked from lttlrck/Int64.js
64-bit Integer type for Javascript based on Int64.js but NodeJS dependency on buffer removed, plus some other small mods.
View Int64.js
// Int64.js
//
// Copyright (c) 2012 Robert Kieffer
// MIT License - http://opensource.org/licenses/mit-license.php
/**
* Support for handling 64-bit int numbers in Javascript (node.js)
*
* JS Numbers are IEEE-754 binary double-precision floats, which limits the
* range of values that can be represented with integer precision to: