Skip to content

Instantly share code, notes, and snippets.

@jblebrun
jblebrun / sleeptimers.go
Created August 6, 2019 02:55
Showing varying behavior of sleep & afterfunc across system suspends depending on presence of Ticker
package main
import(
"time"
"log"
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
@jblebrun
jblebrun / repdupe.go
Created February 21, 2019 04:55
Replace duplicate subtrees
package main
import (
"fmt"
)
type Node struct {
Data string
Left *Node
Right *Node
@jblebrun
jblebrun / multicontext.go
Created March 17, 2018 21:44
MultiContext: Contexts with sibling relationship
// MultiContext allows you to use multiple contexts for cancellation
// allowing for sibling relationship, as well as parent-child relationship.
// This is an experiment, and likely not a good approach.
type MultiContext struct {
ctxs []context.Context
done chan struct{}
err error
}
func NewMultiContext(ctxs []context.Context) *MultiContext {
@jblebrun
jblebrun / stackoverflow.go
Created April 24, 2017 17:34
Weird struct/interface nesting causes stack overflow
package main
type Iface interface {
Method()
}
type Inner struct {
Iface
}
type Outer struct {
@jblebrun
jblebrun / eventsexcerpt.js
Created April 11, 2017 16:29
EventEmitter in node.js master, April 2017
function EventEmitter() {
EventEmitter.init.call(this);
}
/*...*/
EventEmitter.init = function() {
this.domain = null;
if (EventEmitter.usingDomains) {
// if there is an active domain, then attach to it.
domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) {
@jblebrun
jblebrun / eventsexcerpt.js
Created April 11, 2017 16:28
EventEmitter from 0.10.21
function EventEmitter() {
this.domain = null;
if (exports.usingDomains) {
// if there is an active domain, then attach to it.
domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) {
this.domain = domain.active;
}
}
this._events = this._events || {};
@jblebrun
jblebrun / UIView Inspectable Abuse
Created October 17, 2014 17:10
Shadows and corner radius in interface builder!
#import <UIKit/UIKit.h>
@interface UIView (Inspectable)
@property (nonatomic) IBInspectable CGFloat cornerRadius;
@property (nonatomic) IBInspectable BOOL circular;
@property (nonatomic) IBInspectable CGFloat shadowRadius;
@property (nonatomic) IBInspectable CGFloat shadowOpacity;
@property (nonatomic) IBInspectable CGSize shadowOffset;