Skip to content

Instantly share code, notes, and snippets.

@eaigner
eaigner / gist:2820293
Created May 28, 2012 17:55
AppKit Stretchable Image
@implementation NSImage (Stretchable)
- (void)drawStretchableInRect:(NSRect)rect edgeInsets:(NSEdgeInsets)insets operation:(NSCompositingOperation)op fraction:(CGFloat)delta {
void (^makeAreas)(NSRect, NSRect *, NSRect *, NSRect *, NSRect *, NSRect *, NSRect *, NSRect *, NSRect *, NSRect *) = ^(NSRect srcRect, NSRect *tl, NSRect *tc, NSRect *tr, NSRect *ml, NSRect *mc, NSRect *mr, NSRect *bl, NSRect *bc, NSRect *br) {
CGFloat w = NSWidth(srcRect);
CGFloat h = NSHeight(srcRect);
CGFloat cw = w - insets.left - insets.right;
CGFloat ch = h - insets.top - insets.bottom;
CGFloat x0 = NSMinX(srcRect);
@eaigner
eaigner / JSONConvertible.swift
Created April 9, 2016 15:13
Convert Objects to and from JSON
import Foundation
protocol JSONConvertible {
}
extension JSONConvertible {
func toJSON() -> [String: AnyObject] {
var json = [String: AnyObject]()
@eaigner
eaigner / find.go
Last active January 6, 2016 19:03
// Package bench is a package which contains
// programs of Go Benchmark Competition.
package bench
import (
"syscall"
)
// Find reads the text file on the `path`,
// finds the `s` words on the file and
# Setting up dnsmasq for Local Web Development Testing on any Device
Please note, these instructions are for OS X Lion.
First, you need to get the IP address of your machine on your local network. In OS X, the easiest place to find this is in System Preferences > Network. If you're using DHCP on your local network, you will want to make sure your computer requests the same IP address when it renews it's IP address lease. I recommend configuring the DCHP Reservation settings on your router to accomplish this. Otherwise, you can specify a manual address in your network settings:
1. Go to *System Preferences > Network*
1. Click *Advanced...*
@eaigner
eaigner / coord.go
Created August 21, 2013 15:04
Coalesce DB writes using a coordinator
package coord
import (
"sync"
)
// FlushFunc takes all pending objects, writes them, and returns
// the results in the same order, or an error.
type FlushFunc func(v []interface{}) ([]interface{}, error)
@eaigner
eaigner / cloudant.go
Created August 20, 2013 14:39
Cloudant lucene query builder
package cloudant
import (
"bytes"
"reflect"
"strconv"
"strings"
)
const (
@eaigner
eaigner / tree.go
Created August 18, 2013 11:22
In-memory object tree size
package tree
import (
"reflect"
"unsafe"
)
// Cost calculates the memory size of an object tree.
func Cost(v interface{}) uint64 {
return cost(reflect.ValueOf(v))
@eaigner
eaigner / quota.go
Created August 18, 2013 10:27
Quota
package quota
import (
"errors"
"sync"
"time"
)
var QuotaExceededErr = errors.New("quota exceeded")
@eaigner
eaigner / gist:6204685
Last active December 20, 2015 22:19
GoDoc Bookmarklet
javascript:(window.location.href='http://godoc.org/'+window.location.hostname+window.location.pathname)
@eaigner
eaigner / draggable.js
Last active December 20, 2015 15:38
Draggable directive for AngularJS
// Usage: ng-draggable="dragFile($event)"
App.directive('ngDraggable', function ($parse) {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
var fn = $parse(attrs.ngDraggable);
elem[0].draggable = true;
elem.bind('dragstart', function (event) {
scope.$apply(function () {