Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
AquaGeek / main.m
Created May 23, 2015 05:34
Objective-C command line tool
@import Foundation;
int main(int argc, const char * argv[])
{
__block BOOL keepRunning = YES;
// Configure a dispatch source to listen for SIGTERM
// Adapted from https://mikeash.com/pyblog/friday-qa-2011-04-01-signal-handling.html
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
dispatch_source_set_event_handler(source, ^{
@AquaGeek
AquaGeek / LRUCache.swift
Created October 21, 2014 16:32
Swift LRUCache
private class LRUCacheNode<Key: Hashable, Value> {
let key: Key
var value: Value
var previous: LRUCacheNode?
var next: LRUCacheNode?
init(key: Key, value: Value) {
self.key = key
self.value = value
}
@AquaGeek
AquaGeek / heroku-addons.rb
Last active September 26, 2023 01:34
Heroku Addons Breakdown
require 'uri'
require 'net/http'
require 'json'
require 'ostruct'
module Heroku
module Addons
class Addon
attr_accessor :name
@AquaGeek
AquaGeek / CA-simple.geojson
Last active December 30, 2015 04:49
GeoJSON tests
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AquaGeek
AquaGeek / Funny.md
Last active October 24, 2016 02:01
Quotes
Be There: When people need you, they need all of you. Setting aside distractions and judgments to be mentally and emotionally present is a sign of respect. It improves communication and strengthens relationships.
@AquaGeek
AquaGeek / cache.db.sql
Last active July 20, 2022 06:38
iOS Cache.db
CREATE TABLE cfurl_cache_blob_data(
entry_ID INTEGER PRIMARY KEY,
response_object BLOB,
request_object BLOB,
proto_props BLOB,
user_info BLOB
);
CREATE INDEX proto_props_index ON cfurl_cache_blob_data(entry_ID);
CREATE TABLE cfurl_cache_receiver_data(
@AquaGeek
AquaGeek / CurrencySymbol.mm
Created March 19, 2013 10:54
Get position of currency symbol from number formatter
// Courtesy of http://stackoverflow.com/a/12254356/1069919
// NSLocale and CFLocale are toll-free bridged, so if you have an existing
// NSNumberFormatter, you can get its locale and use that instead.
CFLocaleRef usLocale = CFLocaleCreate(NULL, CFSTR("en_US"));
CFNumberFormatterRef usFormatter = CFNumberFormatterCreate(NULL, usLocale, kCFNumberFormatterCurrencyStyle);
CFLocaleRef frLocale = CFLocaleCreate(NULL, CFSTR("fr_FR"));
CFNumberFormatterRef frFormatter = CFNumberFormatterCreate(NULL, frLocale, kCFNumberFormatterCurrencyStyle);
NSString * usString = (__bridge NSString *)CFNumberFormatterGetFormat(usFormatter);
NSString * frString = (__bridge NSString *)CFNumberFormatterGetFormat(frFormatter);
@AquaGeek
AquaGeek / bootstrap.sh
Last active December 12, 2015 09:28
New Workstation Setup
#!/bin/bash
if rvm --version 2>/dev/null; then
gem install soloist
else
sudo gem install soloist --no-ri --no-rdoc
fi
mkdir -p ~/cookbooks; cd ~/cookbooks
@AquaGeek
AquaGeek / png.rb
Last active August 23, 2017 19:35
Ruby code to reverse iPhone PNG optimizations
# Helper method to fix Apple's stupid png optimizations
# Adapted from:
# http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer
# https://github.com/peperzaken/iPhone-optimized-PNG-reverse-script/blob/master/Peperzaken/Ios/DecodeImage.php
# PNG spec: http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html
require 'zlib'
require 'logger'
module PNG