Skip to content

Instantly share code, notes, and snippets.

package com.hubspot.jersey.dropwizard.managed;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.cfg.JaxRSFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.lifecycle.Managed;
@neilpa
neilpa / concatSplices.swift
Last active October 8, 2015 15:17
Building collections from signals[-of-signals] of collection mutations
//
// A half-baked approach (not thread-safe, poor disposable management) for creating
// aggregate collections from multiple signals of collection mutations. In this
// case we are concating multiple mutation streams into a single container. So for
// each inner signal we need to offset subsequent splices by the count of preceding
// items (which can be recovered by scanning previous splices).
//
// Example:
//
// let (first, sink1) = SignalProducer<Splice<Int>, NoError>.buffer()
// Similar to `enumerate` but provides the collection's index type
// rather than an Int for the position
public func iterate<C: CollectionType>(collection: C) -> SequenceOf<(C.Index, C.Generator.Element)> {
var index = collection.startIndex
// type-inference doesn't want to work without this
return SequenceOf { _ -> GeneratorOf<(C.Index, C.Generator.Element)> in
return GeneratorOf {
if index == collection.endIndex {
return nil
@neilpa
neilpa / Random.swift
Last active August 29, 2015 14:19
Randomness
protocol Randomizable {
static func random() -> Self
}
protocol IntervalRandomizable: Randomizable, Comparable {
static func random(interval: HalfOpenInterval<Self>) -> Self
static func random(interval: ClosedInterval<Self>) -> Self
}
extension CGFloat: Randomizable {
@neilpa
neilpa / zipWith.swift
Created February 11, 2015 05:43
Signal.zipWith
private enum Either<T, U> {
case Left(Box<T>)
case Right(Box<U>)
}
public func zipWith<T, U, E>(otherSignal: Signal<U, E>)(signal: Signal<T, E>) -> Signal<(T, U), E> {
return Signal { observer in
var lock = NSRecursiveLock()
lock.name = "org.reactivecocoa.ReactiveCocoa.zipWith"
@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@mpasternacki
mpasternacki / freebsd_on_mbp.md
Created January 23, 2015 17:12
FreeBSD on a MacBook Pro

FreeBSD on a MacBook Pro

Since 2008 or 2009 I work on Apple hardware and OS: back then I grew tired of Linux desktop (which is going to be MASSIVE NEXT YEAR, at least since 2001), and switched to something that Just Works. Six years later, it less and less Just Works, started turning into spyware and nagware, and doesn't need much less maintenance than Linux desktop — at least for my work, which is system administration and software development, probably it is better for the mythical End User person. Work needed to get software I need running is not less obscure than work I'd need to do on Linux or othe Unix-like system. I am finding myself turning away from GUI programs that I used to appreciate, and most of the time I use OSX to just run a terminal, Firefox, and Emacs. GUI that used to be nice and unintrusive, got annoying. Either I came full circle in the last 15 years of my computer usage, or the OSX experience degraded in last 5 years. Again, this is from a sysadmin/developer ki

@jaredru
jaredru / RACSignal+ShareWhileActiveBackport.m
Last active June 30, 2017 02:09
A ReactiveCocoa 2.x `-shareWhileActive` backport
- (RACSignal *)shareWhileActive {
NSRecursiveLock *lock = [[NSRecursiveLock alloc] init];
lock.name = @"com.github.ReactiveCocoa.shareWhileActive";
// These should only be used while `lock` is held.
__block NSUInteger subscriberCount = 0;
__block RACDisposable *underlyingDisposable = nil;
__block RACReplaySubject *inflightSubscription = nil;
return [[RACSignal
@Revolucent
Revolucent / BitwiseOptions.swift
Last active September 22, 2018 12:46
BitwiseOptions implementation for Swift
//
// BitwiseOptions.swift
//
// Created by Gregory Higley on 11/24/14.
// Copyright (c) 2014 Prosumma LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@neilpa
neilpa / nv21-convert.sh
Last active October 12, 2023 13:14
Use ffmpeg to convert raw Android camera frame buffers
# Assuming the raw byte[] buffer from onPreviewFrame was written at $1
INPUT=$1
# Need preview size since we dumped to a raw file w/out header info
SIZE=1280x960
# Converting to JPEG
ffmpeg -f image2 -vcodec rawvideo -s $SIZE -pix_fmt nv21 -i $INPUT out.jpeg
# Converting to PNG