Skip to content

Instantly share code, notes, and snippets.

//http://www.mikeash.com/?page=pyblog/friday-qa-2009-08-14-practical-blocks.html
// NSURLConnection
@implementation NSURLConnection (BlocksAdditions)
+ (void)sendAsynchronousRequest: (NSURLRequest *)request
completionBlock: (void (^)(NSData *data, NSURLResponse *response, NSError *error))block
{
NSThread *originalThread = [NSThread currentThread];
@jnunemaker
jnunemaker / gist:841656
Created February 24, 2011 02:38
all time views across system for http://gaug.es
# How we store all time views across the entire system for http://gauge.es.
# All in one document that gets incremented using MongoDB $inc modifier in
# every track. The $inc increments t, year.t, year.month.t, year.month.day.t
# so we get to the day numbers. These are in EST, as we are in EST and these
# stats are just for us. :) Nothing amazing, but thought I would share.
#
# >> pp View.all_time
{
"_id" => "all_time",
"t" => 502352,
@technoweenie
technoweenie / gist:2155760
Created March 22, 2012 04:03
track meta data with resque jobs, like when it was queued.
module Resque
def push_with_meta(queue, item)
if item.respond_to?(:[]=)
item[:meta] = {:queued_at => Time.now.to_f}
end
push_without_meta(queue, item)
end
class Job
# Returns a Hash of the meta data related to this Job.
@Dania02525
Dania02525 / create_postgres_procedures.exs
Last active June 24, 2016 17:40
Ecto migration to allow postrges to generate local ids in a SaaS app
defmodule Repo.Migrations.CreateProcedures do @doc """
Creates procedure to get and update a local_id number on SaaS apps where
next local id is stored in the tenant table.
Example trigger is given for the user table
"""
use Ecto.Migration
def up do
execute "CREATE OR REPLACE FUNCTION get_local_id(tenant_id integer) RETURNS integer AS $$
import Foundation
protocol Serializable {
static func deserializeInto(bytePtr: UnsafeMutablePointer<UInt8>, bytes: ArraySlice<UInt8>) -> ArraySlice<UInt8>
}
extension Serializable {
typealias WorkaroundSelf = Self
@rwz
rwz / gist:14c0d8a5187b69922bb4
Last active January 28, 2019 11:42
Custom JSON types in AS 4.1+
# config/initializers/lol_json.rb
module ActiveSupport
module JSON
module Encoding
class JSONGemEncoder
BYPASS_JSONIFY = Set.new
alias_method :original_jsonify, :jsonify
@zwaldowski
zwaldowski / CustomFontMetrics.swift
Created June 7, 2017 00:05
[WIP] UIFontMetrics Backport from iOS 11
//
// CustomFontMetrics.swift
//
// Created by Zachary Waldowski on 6/6/17.
// Licensed under MIT.
//
import UIKit
private extension UITraitCollection {
//
// Signal+Extensions.swift
// Khan Academy
//
// Created by Nacho Soto on 10/1/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import ReactiveCocoa
import SwiftUI
import Combine
struct State {
var isCreatingItem: Bool = false
var partialItemName: String = ""
var todoItems: [TodoItem] = []
}
@jtimberman
jtimberman / nginx.conf
Created March 5, 2010 21:01 — forked from johnthethird/nginx.conf
nginx front end for Riak
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;