Skip to content

Instantly share code, notes, and snippets.

@kmikael
kmikael / HomeCollectionViewFlowLayout.swift
Last active March 10, 2021 09:31
Snapping, centering and automatically sizing flow layout
import UIKit
class HomeCollectionViewFlowLayout: UICollectionViewFlowLayout {
var isSetUp = false
override func prepare() {
super.prepare()
setUpIfNeeded()
@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 / 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 / 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

@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 / 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 / preview.rb
Created June 20, 2012 06:15
Preview your README in Marked
#!/usr/bin/env ruby
README = "README.md"
unless File.exist? README
puts 'No README file found'
exit 1
end
`open -a Marked #{README}`
@kmikael
kmikael / quicksort.hs
Created February 11, 2012 18:39
quicksort in Haskell
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = quicksort (filter (< x) xs) ++ [x] ++ quicksort (filter (>= x) xs)
@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