Skip to content

Instantly share code, notes, and snippets.

View thebyrd's full-sized avatar
🌴

David Byrd thebyrd

🌴
View GitHub Profile
@thebyrd
thebyrd / neg.onnx
Created May 4, 2020 22:49
Negate ONNX Model and PyTorch script for generating it.
pytorch1.5:b

01Neg_0"Negtorch-jit-exportZ
0




�b
1
@thebyrd
thebyrd / sqrt.go
Last active January 4, 2016 02:08
As a simple way to play with functions and loops, implement the square root function using Newton's method. In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: To begin with, just repeat that calculation 10 times and see how close you get to the answer for various values (1, 2, 3, ...). Next,…
package main
import (
"fmt"
"math"
)
const Delta = 0.0001
func Sqrt(x float64) float64 {
@thebyrd
thebyrd / stopAndRemove
Created December 30, 2013 17:53
stop and remove all docker containers on a box
docker ps -a | grep 'ago' | awk '{print $1}' | xargs docker rm
@thebyrd
thebyrd / emptyString.js
Created October 28, 2013 17:18
return a string of whitespace of a given length
function emptyString(n) { return new Array(n).join(" ") }
@thebyrd
thebyrd / example.js
Last active December 25, 2015 05:19
A method that will inject npm modules listed as parameters in a constructor.
function SomeConstructor (request, npm, monk) {
// do something with the injected node modules
}
var instance = require('./injector')(SomeConstructor) // create a new instance with dependencies injected
@thebyrd
thebyrd / fatify.js
Created August 21, 2013 03:34
Make all of your tweets look like @fat's
function fatify (str) {
return str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,"").toLowerCase()
}
var list = [1, 3, 5, 5, 23, 23, 4, 3, 3, 6, 7, 4, 2, 2, 5]
var groups = {}
list.forEach(function (n) {
if (groups[n]) groups[n].push(n)
else groups[n] = [n]
})
var result = []
for (var group in groups) result.push(groups[group])
// Make it Nasty
function increment (i) {
i ^= (i & ~-~i) | (~i & -~i)
return i
}
@thebyrd
thebyrd / magicMethod.js
Last active December 19, 2015 05:49
Adds jQuery style getters and setters to a given constructor function.
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
}
var getParamNames = function (func) {
var funStr = func.toString()
return funStr.slice(funStr.indexOf('(')+1, funStr.indexOf(')')).match(/([^\s,]+)/g)
}
@thebyrd
thebyrd / nastyloop.js
Created May 15, 2013 02:33
who knew you could write for loops this way in javascript?
for(var i = 0; i < 10; i++) !function (n) {
console.log(n)
}(i)