Skip to content

Instantly share code, notes, and snippets.

@bprosnitz
bprosnitz / deepequal.go
Last active August 29, 2015 13:59
Debuggable Deep Equal
package build
import (
"fmt"
"reflect"
)
type visit struct {
a1 uintptr
a2 uintptr
@bprosnitz
bprosnitz / deepcopy.go
Created January 20, 2015 19:02
Deep Copy
func deepCopy(rv reflect.Value) reflect.Value {
switch rv.Kind() {
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.String:
return rv
case reflect.Slice:
if rv.IsNil() {
return rv
}
sliceCpy := reflect.MakeSlice(rv.Type(), rv.Len(), rv.Cap())
for i := 0; i < sliceCpy.Len(); i++ {
@bprosnitz
bprosnitz / schrome.sh
Last active August 29, 2015 14:15
Make chrome console log output human readable when using --logtostderr
#!/bin/bash
sed ':a;N;$!ba;s/\(.\{279\}\)\n/\1@#@\n/g' $1 | sed 's/^\[[^]]*\]//g' | sed 's| "<autogenerated>:334: ||g' | sed 's/", source: chrome-extension:\/\/[a-zA-Z0-9.\/]* ([0-9]*)//g' | sed ':a;N;$!ba;s/@#@\n//g'
@bprosnitz
bprosnitz / gist:16df00bcea5cbb7f92a8
Created March 10, 2015 21:42
Error debug hack - log when errors are created to find ones not logged or thrown
var OrigError = Error;
window.Error = function(arg1,arg2,arg3,arg4,arg5,arg6) {
console.log('caught error: ', arg1, arg2,arg3,arg4,arg5,arg6);
console.log(new OrigError().stack)
return new OrigError(arg1,arg2,arg3,arg4,arg5,arg6);
};
@bprosnitz
bprosnitz / replace_regex_match_files
Created March 12, 2015 00:32
Replace regex match in files
for pp in $(grep -r "INITIAL" . | awk -F':' '{print $1}' |sort | uniq); do sed -i 's/INITIAL/FINAL/g' $pp; done
@bprosnitz
bprosnitz / crawlair.json
Last active August 29, 2015 14:17
crawlair.json
[
{
"Origin": "SFO",
"Dest": "HKG",
"Outbound": {
"DayOfWeek": "Saturday",
"DateAdjust": "PlusMinusTwoDays"
},
"Return": {
"DayOfWeek": "Sunday",
@bprosnitz
bprosnitz / fastanimation.js
Last active May 13, 2018 23:32
Speed Up requestAnimationFrame - based Javascript Animation
var oldRequestAnimationFrame = window.requestAnimationFrame;
window.requestAnimationFrame = function(cb) {
var numExtra = 60;
oldRequestAnimationFrame(function(time) {
for (var i = 0; i < numExtra; i++) {
cb(time + 60*1000)
}
});
};
@bprosnitz
bprosnitz / quickerbrownfox.go
Last active August 29, 2015 14:19
Brute force shortest sentence with all the letters
package main
import (
"fmt"
"io/ioutil"
"unicode"
"strings"
)
const noRepeatFirstLetter = true
@bprosnitz
bprosnitz / iframe_contents.html
Created May 6, 2015 19:21
iframe origin security: dispatchEvent vs postMessage
<script>
window.addEventListener('message', function(event) {
console.log('iframe: Got postmessage in origin ' + location.origin + ' from origin: ' + event.origin + '(' + event.data + ')');
});
window.addEventListener('dispatchToIframe', function() {
console.log('iframe: Got dispatchEvent() in origin ' + location.origin + '(from index.html)');
});
setTimeout(function() {
window.dispatchEvent(new CustomEvent('dispatchFromIframe'));
@bprosnitz
bprosnitz / parsemojo.go
Last active November 23, 2015 17:24
Parse mojo bytes and group by allocations
package main
import (
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"log"
)