Skip to content

Instantly share code, notes, and snippets.

@Erkened
Erkened / Applescript
Last active December 6, 2017 16:37
Vim config
on run {input}
set the_path to POSIX path of input
set cmd to "vim " & quoted form of the_path
tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
tell application "Terminal"
activate
if terminalIsRunning is true then
do script with command cmd
else
do script with command cmd in window 1
@Erkened
Erkened / ScrollViewExample+TextField.swift
Last active February 17, 2020 05:16
UIScrollView example, with a textfield that's not covered when the keyboard appears, fully programmatic with AutoLayout. Swift 4.0
//
// ViewController.swift
// Repnote
//
// Created by John Neumann on 05/07/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import UIKit
@Erkened
Erkened / Extensions
Last active September 27, 2017 09:18
Extensions I use often in my projects. Swift 4.0
import Foundation
import UIKit
extension UIColor{
class var random: UIColor {
let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0
let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white
let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
}
@Erkened
Erkened / .bash_profile
Last active January 30, 2018 15:14
Personal bashrc and bash_profile for Terminal on Mac
#!/bin/bash
#
# echo "Loading ${HOME}/.bash_profile"
#source ~/.profile # get my PATH setup
source ~/.bashrc # get my Bash aliases
@Erkened
Erkened / UIScrollViewWithKeyboard
Last active January 29, 2017 19:23
A UIScrollView which scrolls when the keyboard is displayed/hidden. The keyboard is dismissed when tapping outside a responding view like a textfield or textview. Swift 3.0
//
// UIScrollViewWithKeyboard.swift
// Repnote
//
// Created by John Neumann on 29/01/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import UIKit
@Erkened
Erkened / UITextViewWithPlaceholder
Created January 11, 2017 15:26
A UITextView subclass with placeholder. Swift 3.0
//
// UITextViewWithPlaceholder.swift
// Repnote
//
// Created by John Neumann on 11/01/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import UIKit
@Erkened
Erkened / MergeStringsIntoOneMD5Hash.swift
Last active February 1, 2016 14:39
Method to XOR multiple strings into one MD5 hexadecimal hash string in Swift 2. This means that [string1, string2, string3] gives the same MD5 hash as [string3, string2, string1]
// Remember to #import <CommonCrypto/CommonCrypto.h> in the Bridging-Header.h file
/* Example of use
let query = "#test1 #test2 #test3"
let queryArray = query.characters.split{$0 == "#"}.map(String.init)
guard let hash = combineStringsIntoHash(queryArray) else{
return
}
print("hash: \(hash)")
*/
// HOW TO USE PRIVATE COCOAPODS
// SOURCE: http://albertodebortoli.github.io/blog/2014/03/11/cocoapods-working-with-internal-pods/
// SOURCE: https://coderwall.com/p/7ucsva/private-cocoapods
// SOURCE: http://product.hubspot.com/blog/architecting-a-large-ios-app-with-cocoapods
0. INSTALL COCOAPODS
sudo gem install cocoapods
1. CHECK REPOS LOCATION, WHICH SHOULD BE EMPTY
cd ~/.cocoapods/repos/
@Erkened
Erkened / Functions.swift
Last active July 4, 2017 16:00
Functions I reuse often in my apps. Swift 3.0
//
// Functions.swift
// Repnote
//
// Created by Jonathan Neumann on 23/03/2017.
// Copyright © 2017 Audioy. All rights reserved.
//
import Foundation
import UIKit
//
// UIButton_Underlined.swift
// Audio Y
//
// Created by Jonathan Neumann on 31/10/2015.
// Copyright © 2015 Audio Y Ltd. All rights reserved.
//
import UIKit