Skip to content

Instantly share code, notes, and snippets.

View radex's full-sized avatar
🚀
Full reusability

Radek Pietruszewski radex

🚀
Full reusability
View GitHub Profile
@radex
radex / nonoptionals.swift
Created August 28, 2014 09:40
Swift allows you to declare a (non-optional) variable in a local scope without setting its value if the compiler can deduce that the value _will_ be set before it's used.
// This will work:
var url: String
if condition {
url = "http://example.com"
} else {
url = "http://example.org"
}
@radex
radex / NSTimer.md
Last active May 30, 2018 10:33
Swift Extensions: NSTimer

NSTimer is a great example of an over-verbose, outdated Objective-C API. To run a simple line of code after a delay, you need to write a lot of boilerplate crap.

How about this:

NSTimer.schedule(5.seconds) {
  println("Hello world!")
}
@radex
radex / NSStoryboard.md
Last active August 29, 2015 14:05
Swift extensions: NSStoryboard

I enjoy making and playing with little DSL-ish extensions for Cocoa types in Swift. For instance, the code below allows me to write cool

storyboard.VC["foo_bar"]
storyboard.VC.initial

instead of:

require 'csv'
tweets = CSV.read('tweets.csv')
tweets.shift
stats = tweets
.reject { |t| t[5] =~ /^RT/ }
.group_by { |t|
date = Date.parse t[3]
"#{date.year}-#{date.month}"
@radex
radex / pl.yml
Last active December 21, 2015 18:49 — forked from bogdanbeczkowski/pl.yml
pl:
viewer:
comment_on_twitter: 'Skomentuj na Twitterze'
older: 'Starsze'
newer: 'Nowsze'
feed: 'Kanał'
share: 'Udostępnij'
close: 'Zamknij'
next_post: 'Następny wpis'
previous_post: 'Poprzedni wpis'
@radex
radex / yt.sh
Last active December 20, 2015 21:49
Youtube music ripper (for when you find something you can't find anywhere else). Add to your bashrc/zshrc.
# Usage:
# `yt http://www.youtube.com/watch?v=...`
# Downloads a video from youtube, extracts audio out of it and saves as a 256kbps mp3 in Downloads
#
# Requires youtube-dl and ffmpeg
# (OSX: just `brew install youtube-dl ffmpeg`)
yt () {
youtube-dl $1 -o ~/Downloads/%\(title\)s.%\(ext\)s -x --audio-format mp3 --audio-quality 256
}
tell application "Xcode"
activate
end tell
tell application "System Events"
tell application process "Xcode"
click menu item "Stop" of menu 1 of menu bar item "Product" of menu bar 1
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
end tell
end tell
tell application "System Events"
tell application process "Safari"
click menu item 2 of menu 1 of menu item 4 of menu 1 of menu bar item "Develop" of menu bar 1
end tell
end tell
tell application "Safari"
activate
end tell
Pod::Spec.new do |s|
s.name = 'CocoaLumberjack'
s.version = '1.6.1'
s.license = 'BSD'
s.summary = 'A fast & simple, yet powerful & flexible logging framework for Mac and iOS.'
s.homepage = 'https://github.com/robbiehanson/CocoaLumberjack'
s.author = { 'Robbie Hanson' => '[email protected]' }
s.source = { :git => 'https://github.com/robbiehanson/CocoaLumberjack.git',
:commit => 'b5fbf2da1fa35f208683f9afa441b071cc621cd0' }
@radex
radex / compile_xcode.sh
Created March 28, 2013 20:38
Coding some part of an Xcode project in TextMate? Tired of constantly switching between TM and Xcode to compile it? Create this command in your TextMate bundle:
#!/bin/zsh
osascript <<SCRIPT
tell application "Xcode"
activate
end tell
tell application "System Events"
tell application process "Xcode"
click menu item "Stop" of menu 1 of menu bar item "Product" of menu bar 1