Skip to content

Instantly share code, notes, and snippets.

@kmikael
kmikael / HomeCollectionViewFlowLayout.swift
Last active August 9, 2024 21:06
Snapping, centering and automatically sizing flow layout
import UIKit
class HomeCollectionViewFlowLayout: UICollectionViewFlowLayout {
var isSetUp = false
override func prepare() {
super.prepare()
setUpIfNeeded()
@kmikael
kmikael / subsequences.py
Last active April 21, 2017 17:31
Generate `count` weights from a range, `seq` that add up to a given `target`
def subsequences(count, seq = range(5, 40, 5), target = 100, partial = []):
if count == 0:
return
s = sum(partial)
if s >= target:
return
if s == target or (count == 1 and (target - s) in seq):
@kmikael
kmikael / AnimationControllerForPresentedController.swift
Last active May 11, 2017 15:25
[WIP] Creating a Custom Presentation Transition
// https://developer.apple.com/reference/uikit/uiviewcontrollertransitioningdelegate
class AnimationController: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.2 // The duration of the animation
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// Since you are presenting a new view controller, you primarily need the new view controller
@kmikael
kmikael / asyncAfter.md
Created November 25, 2016 18:05
Quick: Easy DispatchTime

This also works as a short and out-of-the-box alternative:

DispatchQueue.main.asyncAfter(deadline: .now() + 5.0 ) { /* */ }

Thanks to:

public func +(time: DispatchTime, seconds: Double) -> DispatchTime
@kmikael
kmikael / eject.sh
Created August 9, 2014 09:17
Eject every disk whose ejectable is true (shell script)
osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
@kmikael
kmikael / eject.applescript
Created August 8, 2014 20:17
Eject every disk whose ejectable is true
tell application "Finder"
eject (every disk whose ejectable is true)
end tell
@kmikael
kmikael / dispatch_async
Created June 13, 2014 15:06
Update `dispatch_async` to take a default `queue`
import Dispatch
func dispatch_async(queue: dispatch_queue_t = dispatch_get_main_queue(), block: dispatch_block_t) {
Dispatch.dispatch_async(queue, block)
}
dispatch_async {
// Update the UI
}
@kmikael
kmikael / pg_parse_url.sql
Last active August 29, 2015 14:02
PostgreSQL Parsers
SELECT t.alias, p.token
FROM ts_parse('default', 'http://www.postgresql.org/docs/9.4/static/textsearch-parsers.html') AS p
NATURAL JOIN ts_token_type('default') AS t;
-- alias | token
-- ----------+------------------------------------------------------------
-- protocol | http://
-- url | www.postgresql.org/docs/9.4/static/textsearch-parsers.html
-- host | www.postgresql.org
-- url_path | /docs/9.4/static/textsearch-parsers.html
@kmikael
kmikael / README.md
Last active December 26, 2015 22:09
Generate a UIColor constructor from a given hex string

Given #f7dd37, this workflow will generate a line like this [UIColor colorWithRed:247.0 / 255.0 green:221.0 / 255.0 blue:55.0 / 255.0 alpha:1.0] and paste it into the frontmost application.

@kmikael
kmikael / README.md
Created July 29, 2012 10:16
Alfred Extensions to create new reminders or notes

Alfred Extensions to create new reminders or notes

OS X Mountain Lion ships with two new apps, Reminders and Notes, which are basically OS X counterparts of the standard iOS apps with the same names. One nice thing about these new apps is that they are scriptable.

This means that I was able to create two simple AppleScripts and thus an Alfred extensions to make a new reminder in the default list and to make a new note in the default folder.

You can view the sources of the AppleScripts below.

Examples