Skip to content

Instantly share code, notes, and snippets.

View lukaskollmer's full-sized avatar
👻
procrastinating

Lukas Kollmer lukaskollmer

👻
procrastinating
View GitHub Profile
@lukaskollmer
lukaskollmer / NSDate+Compare.swift
Created November 8, 2015 12:44
NSDate (Compare)
// MARK: NSDate + Compare
public func <(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == .OrderedAscending
}
public func ==(a: NSDate, b: NSDate) -> Bool {
return a.compare(b) == .OrderedSame
}
extension NSDate: Comparable { }
@lukaskollmer
lukaskollmer / daringfireball.net.js
Created December 31, 2015 13:14
dotjs configuration for daringfireball to make the website nicer
$('body').css({
'background-color' : 'white',
'font-family' : 'Avenir-Roman',
'line-height' : '200%'
});
$('div').css({
'color' : 'black',
'font-size' : '110%'
});
@lukaskollmer
lukaskollmer / Add Twitter Profile Picture to iOS Contacts.py
Last active February 15, 2016 05:45
Load Twitter profile pictures and set them as image to your iOS contacts
import twitter
import json
import urllib
import contacts
import console
from objc_util import *
import ui
import os
from PIL import Image
import webbrowser
@lukaskollmer
lukaskollmer / SequenceType+Exclude.swift
Last active May 7, 2016 16:17
Swift SequenceType exclude
extension SequenceType where Generator.Element : Equatable {
/// Returns `self`, excluding `element`
@warn_unused_result
public func excluding(element: Self.Generator.Element) -> [Self.Generator.Element] {
return self.filter({$0 != element})
}
public func excluding(element: [Self.Generator.Element]) -> [Self.Generator.Element] {
return self.filter({!(element.contains($0))})
}
@lukaskollmer
lukaskollmer / MediaPicker.py
Created May 12, 2016 18:36
Pythonista media picker example
# coding: utf-8
import console
from objc_util import *
console.clear()
importFramework('MediaPlayer')
MPMediaPickerController = ObjCClass('MPMediaPickerController')
@lukaskollmer
lukaskollmer / ImportFramework.py
Created May 12, 2016 18:41
Import ObjC frameworks
from objc_util import *
class ImportFrameworkError(Exception):
def __init__(self, name):
self.name = name
def __str__(self):
return 'Couldn\'t import {}.framewrork. (Neither from public, nor from private frameworks)'.format(self.name)
@lukaskollmer
lukaskollmer / is2or3.py
Created May 13, 2016 20:54
Check if a script is running in Pythonista 2 or 3
import os
import sys
import plistlib
def get_bundle_identifier():
plist = plistlib.readPlist(os.path.abspath(os.path.join(sys.executable, '..', 'Info.plist')))
return '{CFBundleIdentifier}'.format(**plist)
def is_pythonista_3():
return get_bundle_identifier() == 'com.omz-software.Pythonista3'
@lukaskollmer
lukaskollmer / photos_legacy.py
Created May 21, 2016 13:16
Add legacy functions to the photos module
import photos
def pick_an_image(show_albums=False, include_metadata=False, original=True, raw_data=False, multi=False):
assets = photos.get_assets()
return photos.pick_asset(assets, multi=multi).get_image()
photos.pick_image = pick_an_image
@lukaskollmer
lukaskollmer / get_available_memory.py
Last active October 2, 2023 11:41
Get memory stats in Pythonista using ctypes
#!/usr/bin/env python3
# Copyright (c) 2016 Lukas Kollmer<lukas@kollmer.me>
from ctypes import *
from objc_util import ObjCClass
NSProcessInfo = ObjCClass('NSProcessInfo')
NSByteCountFormatter = ObjCClass('NSByteCountFormatter')
//
// UIFont+CustomFont.m
//
// Created by Lukas Kollmer on 6/13/15.
// Copyright (c) 2015 Lukas Kollmer. All rights reserved.
//
@import UIKit;
#import <objc/runtime.h>