Skip to content

Instantly share code, notes, and snippets.

Videos

@saru2020
saru2020 / git-author-rewrite.sh
Created June 3, 2017 16:14
Used to change the Author's (Name & Email) in all the commits in Git History.
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
var a = 2
var b = 4
func add(x, y) {
return x + y
}
func add(x, y) {
return x + y
}
//Imperative Programming
var total = 0
for i in 1...10 {
total += i
}
print("Imperative: total: ", total); // prints 55
//Functional Programming
func sum(start: Int, end: Int, total: Int) -> Int {
if (start > end) {
return total;
}
return sum(start: start + 1, end: end, total: total + start)
}
print("Functional: total: ", sum(start: 1, end: 10, total: 0)); // prints 55
struct Contact {
var firstName: String
var lastName: String
var email: String
var age: Int
var duration: Int
}
let contacts = [
Contact(firstName: "first", lastName: "1", email: "some@one1.com", age: 20, courseDuration: 12),
Contact(firstName: "Second", lastName: "2", email: "some@one2.com", age: 22, courseDuration: 16),
Contact(firstName: "Third", lastName: "3", email: "some@one3.com", age: 30, courseDuration: 22)
]
//Get just the name of the contacts into a separate array
//Imperative Programming
var contactNamesImp = [String]()
for contact in contacts { // for each
contactNamesImp.append(contact.firstName)
}
print(contactNamesImp)
//Functional Programming
let contactNames = contacts.map({
return $0.firstName + " " + $0.lastName
})
print(contactNames)