Skip to content

Instantly share code, notes, and snippets.

View JanGorman's full-sized avatar
:shipit:

Jan Gorman JanGorman

:shipit:
View GitHub Profile
@JanGorman
JanGorman / git-svn-pull-branch
Created December 2, 2010 14:38
Needs an environment variable named GIT_SVN_URL that points to the branches folder of the SVN repo you're tracking, ie. export GIT_SVN_URL=https://your.repo.com/project/branches and then you can git-svn-pull-branch <svn branch> <local name> <rev spec>
#!/bin/sh
CMD=$(basename $0)
if [ $# != 3 ]; then
echo "usage $CMD <svn branch> <local name> <rev spec>"
exit 1
fi
if [ ! -d .git ]; then
@JanGorman
JanGorman / git-svn-relocate.sh
Created February 21, 2012 14:41
Fix git after SVN relocate
#!/bin/sh
# Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ]
then
echo "Invoke this script with two command-line arguments (old and new SVN URLs)."
exit $E_NO_ARGS
fi
@JanGorman
JanGorman / git-svn-externals.js
Created March 12, 2012 13:03
Link svn:externals in a git svn clone
// Run from the root path of your git-svn clone as
// node git-svn-externals.js
var exec = require('child_process').exec,
celeri = require('celeri'),
_ = require('underscore')
;
var spinner = celeri.loading('Finding svn externals. This will take a couple of minutes. ');
@JanGorman
JanGorman / order.swift
Created June 16, 2014 12:51
Readable Sorting
class Person {
var age: Int
var name: String
init(age: Int, name: String) {
self.age = age
self.name = name
}
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let request = NSURLRequest(URL: NSURL(string: "http://www.duckduckgo.com"))
// let request = NSURLRequest(URL: NSURL(string: "http://www.google.com"))
// let request = NSURLRequest(URL: NSURL(string: "http://www.apple.com"))
@JanGorman
JanGorman / PrimeFactors.swift
Last active August 22, 2017 14:16
Prime factors Kata
//: Playground - noun: a place where people can play
import UIKit
func primeFactors(of int: Int) -> [Int] {
var n = int
var factors: [Int] = []
var divisor = 2
while n > 1 {
while n % divisor == 0 {
struct Configuration: BooleanType {
private let isActiveConfiguration: Bool
// Extend to your heart's content, e.g. size classes
init(idiom: UIUserInterfaceIdiom? = nil, os: NSOperatingSystemVersion? = nil) {
var configuration = true
if let idiom = idiom {
configuration = idiom == UIDevice.currentDevice().userInterfaceIdiom
}
@JanGorman
JanGorman / init.swift
Created May 29, 2015 16:27
Smart Swift Initialisation
class Foo {
// Keep default values for optionals anyway since we can do shorter self.init calls
// when the call is unambiguous from the convenience init
private init(image: UIImage? = nil, images: [UIImage]? = nil, imageURL: NSURL? = nil, blurStyle: UIBlurEffectStyle = .Dark) {
// init
}
// By exposing convenience initialisers that take mutually exclusive parameters
// we remove the need to do any kind of assertion on them
class PasswordGenerator {
private static let Lowercase = "abcdefghijklmnopqrstuvwxyz".split()
private static let Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split()
private static let Symbols = "!@#$%^&*?".split()
private static let Numbers = "0123456789".split()
class func generate(length: Int = 10) -> String {
let allLetters = (Lowercase + Uppercase + Symbols + Numbers).shuffle()
var password = ""
let opts : [Int?] = [1, nil, 2, nil, nil, 5,
nil, 3, 8, 11, 2, 6, nil, 9]
// "1 2 5 3 8 11 2 6 9 "
for case let x? in opts {
print("\(x) ", false)
}