Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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) -&gt; DispatchTime
@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