Skip to content

Instantly share code, notes, and snippets.

View dlo's full-sized avatar
Always shipping.

Dan Loewenherz dlo

Always shipping.
View GitHub Profile
@dlo
dlo / gradient.m
Created January 2, 2014 01:10
Draw a linear gradient in Objective-C
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.0, 1.0 };
NSArray *colors = @[(__bridge id)HEX(0xC9C9CEFF).CGColor, (__bridge id)[UIColor whiteColor].CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);
UIGraphicsBeginImageContext(CGSizeMake(1, 32));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, 32), 0);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@dlo
dlo / Auto-layout-keyboard-adjustment.md
Last active February 26, 2021 07:33
How to adjust a view's height with Auto Layout when a keyboard appears or disappears in iOS 7.

This gist outlines how to resize a view when a keyboard appears using Auto Layout (there are a bunch of code samples out there that manually adjust the view's frame, but that's just so 2013). The method I outline below works universally on both iPhone and iPad, portrait and landscape, and is pretty darn simple.

Setting Up

The first thing to do is to define our containing view controller, the view, and the bottom constraint that we'll use to adjust its size.

Here's HeightAdjustingViewController.h. We don't need to expose any public properties, so it's pretty bare.

@dlo
dlo / .tarsnaprc
Last active January 26, 2021 03:16
I guess this is a pretty good OS X tarsnap configuration.
### Recommended options
humanize-numbers
# Tarsnap cache directory
cachedir /usr/local/tarsnap-cache
# Tarsnap key file
keyfile ~/.tarsnap/tarsnap.key
# Don't archive files which have the nodump flag set
@dlo
dlo / handle.ts
Created December 18, 2020 23:57 — forked from destroytoday/handle.ts
/*
Typescript erroring:
---
Type 'Promise<(T | undefined)[] | [any, undefined]>' is not assignable to type 'Promise<[void | Error, void | T]>'.
Type '(T | undefined)[] | [any, undefined]' is not assignable to type '[void | Error, void | T]'.
Type '(T | undefined)[]' is not assignable to type '[void | Error, void | T]'.
Target requires 2 element(s) but source may have fewer.ts(2322)
*/
export default function <T> (promise: Promise<T>): Promise<[Error | void, T | void]> {
@dlo
dlo / .gitignore
Created February 9, 2011 17:47
Using filesystem events and git to version my Notational Velocity notes
Interim Note-Changes
.DS_Store
@dlo
dlo / export_foursquare_checkins.py
Last active February 27, 2020 12:27
Download all your Foursquare checkins with Python.
# pip install requests
import requests
import json
url_template = 'https://api.foursquare.com/v2/users/self/checkins?limit=250&oauth_token={}&v=20131026&offset={}'
# If you navigate to https://developer.foursquare.com/docs/explore, Foursquare
# will generate an OAuth token for you automatically. Cut and paste that token
# below.
token = ""
@dlo
dlo / generate_iconset_contents.py
Created November 1, 2017 01:01
Automatically generate a Content.json file for an iOS icon set from a list of iOS icons in a folder.
#!/usr/bin/env python
# Usage: ls *.png | ./generate_iconset_contents.py
import sys
import re
import json
r = re.compile(".*(AppStore|iPhone|iPad).*-([\d\.]+)(@\dx)?\.png")
@dlo
dlo / allpinboard.py
Last active September 5, 2019 15:26 — forked from ttscoff/allpinboard.rb
Python version of https://gist.github.com/3773519 that pulls all bookmarks on the first sync, and does incremental updates afterwards. Also uses the Mac OS X keychain to retrieve your password so it doesn't need to live in a file on your computer in plain text.
#!/usr/bin/env python
"""
This script is designed to generate a simple html file with _all_ of your
Pinboard.in bookmarks The HTML file can be added to Launchbar's index as a
custom bookmark file and you can search your entire Pinboard.in collection
instantly from Launchbar (by title only). It includes any applied tags as part
of the title to aid in searching.
You should edit the `username`, `bookmark_filename`, and `local_timezone`
Verifying my Blockstack ID is secured with the address 1NBmXpzWD5qHQNR7gB7Weod1d7FhFBXeuV https://explorer.blockstack.org/address/1NBmXpzWD5qHQNR7gB7Weod1d7FhFBXeuV
@dlo
dlo / example.yaml
Created October 8, 2013 15:52
Generating the current date in Django fixtures with YAML
- dt: &now
- !!python/object/apply:apply
- !!python/object/apply:getattr
- !!python/name:datetime.datetime
- now
- []
- model: app.user
pk: 1
fields: