Skip to content

Instantly share code, notes, and snippets.

Avatar
Always shipping.

Dan Loewenherz dlo

Always shipping.
View GitHub Profile
View 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 Feb 9, 2011
Using filesystem events and git to version my Notational Velocity notes
View .gitignore
Interim Note-Changes
.DS_Store
@dlo
dlo / Auto-layout-keyboard-adjustment.md
Last active Aug 26, 2020
How to adjust a view's height with Auto Layout when a keyboard appears or disappears in iOS 7.
View Auto-layout-keyboard-adjustment.md

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 / surround.md
Created Dec 25, 2009
surround.vim reference
View surround.md

Deleting

Text              Command    New Text
---------------   -------    -----------
'Hello W|orld'    ds'        Hello World
(12|3+4*56)/2     ds(        123+4*56/2
<div>fo|o</div>   dst        foo
@dlo
dlo / export_foursquare_checkins.py
Last active Feb 27, 2020
Download all your Foursquare checkins with Python.
View export_foursquare_checkins.py
# 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 Nov 1, 2017
Automatically generate a Content.json file for an iOS icon set from a list of iOS icons in a folder.
View generate_iconset_contents.py
#!/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")
View admin.py
"""
Copyright (C) Daniel Loewenherz, 2009. All Rights Reserved.
"""
from django.contrib import admin
from linonia.lin.models import *
class PhotoAdmin(admin.ModelAdmin):
list_display = ['hash', 'album']
@dlo
dlo / allpinboard.py
Last active Sep 5, 2019 — 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.
View allpinboard.py
#!/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`
View gist:f41d3a579d7603814d904362d643766e
Verifying my Blockstack ID is secured with the address 1NBmXpzWD5qHQNR7gB7Weod1d7FhFBXeuV https://explorer.blockstack.org/address/1NBmXpzWD5qHQNR7gB7Weod1d7FhFBXeuV
View generate_health_xml.py
#!/usr/bin/env python
import json
import datetime
def date_from_row(row):
year = row['year']
month = row['month']
day = row['day']
hour = row['hour']
You can’t perform that action at this time.