Skip to content

Instantly share code, notes, and snippets.

View mlvea's full-sized avatar
🌴
On vacation

Phanerozoic mlvea

🌴
On vacation
View GitHub Profile
@mlvea
mlvea / enemarate_with_index.swift
Last active August 29, 2015 14:17
Objective c array enumeration in swift
//Teams play for Cricket world cup 2015 super 8
var superEight = ["NZ","Aus","SL","Bang","Ind","SA","Pak","WI"]
for (index, value) in enumerate(superEight){
println("Team \(index+1) : \(value)")
}
@mlvea
mlvea / modify_array.swift
Created March 15, 2015 02:03
Arrays in swift
//My favourite movies
var favouriteMovies = ["Inception","Theory of Everything","Fifty Shades of Grey"]
//I have new favourite
favouriteMovies += "PK"
//Ohh forgot The Hunger Games
favouriteMovies += ["Hunger Games","Catching Fire","Mocking Jay"]
//Hmm. Replace Fifty Shades and PK with new favourites I happened to watch recently -> Interstellar and The Social Network
@mlvea
mlvea / optionals_basic.swift
Last active August 29, 2015 14:17
Optionals and Dictionary
let netWorthOfBillionaires = ["Bill Gates":78.5,"Carlos Slim Helu":71,"Warren Buffett":70.9]
let possibleNetWorth = netWorthOfBillionaires["Tim Cook"]
//Type of the possibleNetWorth is inferred to Double?
//Know what! Tim cook is not a billionair yet. His net worth is aroung $400 million
//Thats why he is not in our list. But who knows. He might becomes a billionair
if (possibleNetWorth != nil){
@mlvea
mlvea / 01_functions.swift
Last active August 29, 2015 14:17
Swift Funtions
//Swift Function
func keepCalmAndLearnSwift(){
println("Ohh yeah. Learning Swift")
}
//Swift function with parameters
func keepCalmAndLearn(language: String){
println("Ohh yeah. Learing \(language)")
@mlvea
mlvea / currencies.json
Created March 17, 2015 16:07
Common currencies as an array
[
{
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},
@mlvea
mlvea / mogenerator_build.sh
Created March 20, 2015 12:07
Mogenerator Run Script
MODEL_PATH="$PROJECT_DIR/<RootDirectory>/<ModelName>.xcdatamodeld"
OUTPUT_DIRECTORY="$PROJECT_DIR/<RootDirectory>/Classes/Model"
mogenerator --v2 --model $MODEL_PATH --output-dir $OUTPUT_DIRECTORY
@mlvea
mlvea / valid_invalid_enum_and_why.swift
Last active August 29, 2015 14:27
Swift Valid and Invalid enums with reasons
//Define a class Cat
class Cat {
}
enum EnumWithRaw : Cat{
/*
INVALID
[Error]: Raw Type Cat is not convertible from any literal
[Reason]: Raw value of enum have to be of type strings, characters, or any of the integer or floating-point number types.
@mlvea
mlvea / build_number_overlay.sh
Created September 22, 2015 14:14
bash scripts to build number overlay on iOS app icons
IFS=$'\n'
function tagAllIcons(){
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
APP_ICONS_PATH="${PROJECT_DIR}/BuildNumberTagger/Images.xcassets/AppIcon.appiconset"
REFERENCE_ICONS_PATH="${PROJECT_DIR}/BuildNumberTagger/AppIconReference.xcassets"
for ICON_PATH in $(find ${REFERENCE_ICONS_PATH} -name "*Icon*.png")
@mlvea
mlvea / UIView+AutoLayout.swift
Created September 28, 2015 13:45
UIView extension to bind subview bounds to its superview
extension UIView{
func boundInside(superView: UIView){
self.translatesAutoresizingMaskIntoConstraints = false
superView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[subview]-0-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics:nil, views:["subview":self]))
superView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[subview]-0-|", options: NSLayoutFormatOptions.DirectionLeadingToTrailing, metrics:nil, views:["subview":self]))
}
@mlvea
mlvea / allemail.txt
Created October 4, 2015 10:59
Almost All emails regex. Got this at http://stackoverflow.com/a/719543
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)