Skip to content

Instantly share code, notes, and snippets.

@ericcj
ericcj / DNSTimeoutInterceptor.java
Created February 28, 2017 17:10
Naive timeout for DNS resolution using a thread per request
/**
* Based on http://stackoverflow.com/questions/693997/how-to-set-httpresponse-timeout-for-android-in-java/31643186#31643186
* as per https://github.com/square/okhttp/issues/95
*/
private static class DNSTimeoutInterceptor implements Interceptor {
long mTimeoutMillis;
public DNSTimeoutInterceptor(long timeoutMillis) {
mTimeoutMillis = timeoutMillis;
}
@ericcj
ericcj / DeadlineCall.java
Created February 28, 2017 16:57
An okhttp3.Call with a deadline timeout from the start of isExecuted until ResponseBody.source() is closed or unused.
package com.pushd.util;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
@ericcj
ericcj / README.md
Last active December 20, 2023 15:41 — forked from siannopollo/README.md
Pluck in batches

pluck_in_batches

Sometimes you need to iterate over a ton of items and you don't want the overhead of creating AR objects out of all of them. Hell, you only need a few things! Well, #pluck has your back.

But what if you want to iterate over many tonnes of items?

Pluck in batches to the rescue!

This fork works on any orderable primary key not just integers just like http://api.rubyonrails.org/classes/ActiveRecord/Batches.html#method-i-find_in_batches

@ericcj
ericcj / autojoin.user.js
Last active November 14, 2017 21:18 — forked from ezza/autojoin.user.js
G+ Hangouts Autojoin without setTimeout leak
// ==UserScript==
// @name G+ Hangouts Autojoin
// @description Automatically click the join button when loading a hangout
// @include https://plus.google.com/hangouts/_/*
// @match https://plus.google.com/hangouts/_/*
// @version 0.1.0
// ==/UserScript==
(function(){
@ericcj
ericcj / ALAssetsGroup+TLEnumeration.h
Created August 29, 2013 13:18
enumerate camera roll in actual reverse chronological order
#import <AssetsLibrary/AssetsLibrary.h>
@interface ALAssetsGroup (TLEnumeration)
// assume camera roll is k-ordered by date
- (void)enumerateAssetsReverseKOrdered:(ALAssetsGroupEnumerationResultsBlock)enumerationBlock;
@end
@ericcj
ericcj / UIView+TLLayout.h
Created August 29, 2013 13:15
crazy that hiding a uiview doesn't affect its autolayout constraints. here's a category for the rest of the world who uses dynamic interfaces
#import <UIKit/UIKit.h>
@interface UIView (TLLayout)
@property (nonatomic, strong) NSArray *hiddenConstraints;
// set hidden and remove any constraints involving this view from its superview
- (void)hideAndRemoveConstraints;
- (void)showAndRestoreConstraints;