Skip to content

Instantly share code, notes, and snippets.

View NicholasTD07's full-sized avatar

Nicholas T. NicholasTD07

View GitHub Profile
static func getPrimes(to n: Int) -> [Int] {
let xmody = (1...n)
.map { x in (1...n).map { y in x % y } }
let primes = xmody
.map { mods in
mods.enumerate()
.filter { y, mod in mod == 0 }
.map { y, mod in y + 1 } // divisors for x
}
@NicholasTD07
NicholasTD07 / things-go-wrong-in-swift-2.1.swift
Created January 12, 2016 10:58
Things go wrong in Swift 2.1
/// # Things go wrong in Swift 2.1
/// ## A protocol overriding/giving default implementation to its parent's methods
/// If you have a class conform to this protocol and try compile, you will get segmentation fault 11.
protocol SingleSectionTableViewDataSource: UITableViewDataSource {
typealias ItemType
var items: [ItemType] { get set }
}
@NicholasTD07
NicholasTD07 / weird-xcode-problems?.md
Created November 26, 2015 08:13
Solution to (some) Weird Xcode Problems

Weird Xcode Problems?

rm -rf /Library/Developer/ (Or, you can rename it. It's probably safer to rename it.)

This fixed

  • Xcode 6.4: icons in Simulator were garbled
@NicholasTD07
NicholasTD07 / Blocked-by-GFW.md
Last active November 26, 2015 06:56
Fucking GFW making life even harder.

Blocked by GFW

GFW makes it harder (by blocking things) for me to use these:

  • Anything use https
  • berks
  • git
  • carthage
  • Websites (some)
  • Google
@NicholasTD07
NicholasTD07 / how-to-download-iOS-simulator-in-command-line-and-install-it.md
Last active November 10, 2023 19:39
How to Download iOS Simulator (Xcode) in Command Line and Install it

How to Download iOS Simulator (Xcode) in Command Line and Install it

For faster connection speed and more flexibility.

Steps

  1. Start Xcode in command line by running this in commandline /Applications/Xcode.app/Contents/MacOS/Xcode
  2. Start downloading of the simulator
  3. Cancel it. YES CANCEL IT!
  4. You will get a message like this:
@NicholasTD07
NicholasTD07 / TimeTracking.swift
Last active March 5, 2021 01:26
I use this to know how many hours I work a day.
#!/usr/bin/env xcrun swift
// Usage: path/to/TimeTracking.swift
// Go to bottom to see how it's used.
// The MIT License (MIT)
// Copyright (c) 2015 Nicholas T.
// Permission is hereby granted, free of charge, to any person obtaining a copy
@NicholasTD07
NicholasTD07 / clean-up-merged-branches.py
Last active October 1, 2015 07:36
Remove all merged branches
#!/usr/bin/env python2
# Remove all merged branches, except ignored as specified in IGNORE_BRANCHES
import subprocess
IGNORE_BRANCHES = ['master', 'develop']
def main():
checkout_branch('master')
merged_branches_except_ignored = filter_branches_with_ignores(
@NicholasTD07
NicholasTD07 / iOS-UI-in-code-with-SnapKit.swift
Last active August 27, 2015 09:07
Doing iOS UI in code with SnapKit
import UIKit
import SnapKit
class SomeViewController: UIViewController {
var addButton = UIButton()
var helloWorldLabel = UILabel()
override func viewDidLoad() {
let superView = view
let views = [
//
// NSDate+timeAgo.swift
//
//
// Created by Nicholas Tian on 19/08/2015.
// Copyright (c) 2015 nickTD. All rights reserved.
//
import Foundation
@NicholasTD07
NicholasTD07 / all-fonts-in-iOS-app.swift
Created August 17, 2015 08:07
Find all the font in an iOS app
for fontFamily in UIFont.familyNames() {
println("family: \(fontFamily)")
for font in UIFont.fontNamesForFamilyName(fontFamily as! String) {
println("font: \(font)")
}
}