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 / 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 / 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`
@dlo
dlo / mixpanel-delete-people.py
Created April 12, 2018 00:38 — forked from JorgenHookham/mixpanel-delete-people.py
Mixpanel Delete People
"""
This is from mixpanel customer service, I just PEP8ified it. Update api key, secret and token.
You can define which users you want to delete on line 125. Right now it will delete users who haven't
been seen in over 7 weeks. You will recieve a confirmation prompt before the people are deleted.
"""
import hashlib
import time
import urllib
import base64
@dlo
dlo / better-ssh-authorized-keys-management.md
Created February 5, 2018 01:04 — forked from sivel/better-ssh-authorized-keys-management.md
Better SSH Authorized Keys Management

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server:

@dlo
dlo / NSDecimalNumber.swift
Last active November 13, 2017 10:23 — forked from mattt/NSDecimalNumber.swift
NSDecimalNumber Additions for Swift 3 - Updated
import Foundation
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .orderedSame
}
public func <(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .orderedAscending
}
@dlo
dlo / sample.py
Last active August 25, 2016 15:24 — forked from afroisalreadyinu/sample.py
import operator
def build_book_inventory(book_ids, shops):
shop_labels = map(operator.itemgetter('label'), shops)
books = Persistency.books_table.read(shops=shop_labels, books=book_ids)
inventory = {}
for book in books:
shop_inventory = inventory.setdefault(book['shop_label'])
book_inventory = shop_inventory.setdefault(book['cell_label'], {})
@dlo
dlo / dispatch_once.swift
Created June 20, 2016 01:43 — forked from kristopherjohnson/dispatch_once.swift
Example of using dispatch_once() in Swift
import Foundation
var token: dispatch_once_t = 0
func test() {
dispatch_once(&token) {
println("This is printed only on the first call to test()")
}
println("This is printed for each call to test()")
}
@dlo
dlo / gist:8042879
Last active December 31, 2015 20:49
//
// TMSerialAnimationQueue.h
// Orangina
//
// Created by Bryan Irace on 10/9/13.
// Copyright (c) 2013 Tumblr. All rights reserved.
//
/**
Contains boilerplate for performing animations serially, without blocking the main thread.
@dlo
dlo / gist:4331171
Created December 18, 2012 19:34 — forked from anonymous/gist:4331127
40 random alphanumeric characters in Python
''.join(random.sample(string.letters+string.digits, 40))
@dlo
dlo / patch.sh
Last active October 1, 2015 02:18 — forked from lambdalisue/patch.sh
Ubuntu 11.10 Python Image Library (PIL) 1.1.7 installation via pip patch
#!/bin/sh
# Ref: http://ubuntuforums.org/showthread.php?t=1751455
# Uninstall PIL
# sudo pip uninstall PIL -q
# Install required libs
apt-get --yes install build-essential python-dev zlib1g-dev liblcms1-dev libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
# Link to correct location