Skip to content

Instantly share code, notes, and snippets.

View furixturi's full-sized avatar
😈

Xiaoli Shen furixturi

😈
View GitHub Profile
@furixturi
furixturi / .envrc
Last active March 29, 2023 10:50
Use direnv to switch Github account between folders
# Use another github account in a certain folder
# Credit: http://suguru03.hatenablog.com/entry/2018/01/26/162826 (https://github.com/suguru03)
#
# Note: This requires installing direnv, I used homebrew for the installation
#
# Suppose for a certain github account, a new SSH key "id_rsa_xxx" was created and added in Github
# Create a .envrc file in the folder you want to use this account with the following line:
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_xxx"
@furixturi
furixturi / .gitconfig
Last active March 8, 2018 04:28
global git config
[core]
excludesfile = /Users/01123805/.gitignore_global
[diff]
tool = "sourcetree"
[difftool]
prompt = true
[difftool "sourcetree"]
cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
@furixturi
furixturi / .gitignore
Created November 20, 2017 05:02 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
// The parent class Shape
class Shape {
var className: String = "Shape"
var numOfSides: Int = 0
init(numOfSides: Int) {
self.numOfSides = numOfSides
}
func simpleDescription() -> String {
class Talkie {
var words: String = "I talk to others." {
willSet {
print("Words are going to be changed to: \(newValue)")
}
didSet {
print("Words are changed to: \(words)")
}
}
}
// class with getter setter
class EquilateralTriangle {
private var sideLength: Double = 0 //a private property that can only be set at instantiation
init(sideLength: Double) {
self.sideLength = sideLength
}
var perimeter: Double {
get {
// Class with init
class MyClassWithInit {
var myProperty: String
var myOtherProperty: Int
init(myProperty: String, otherProperty: Int) {
self.myProperty = myProperty // Here you need "self" only because the property name is the same as the parameter name
myOtherProperty = otherProperty // See, here you don't need "self"
}
// To instantiate an object from MyClass
let myObj = MyClass()
myObj.myProperty // 0
myObj.myMethod() // 0
// To declare a class
class MyClass {
var myProperty = 0
func myMethod() {
return myProperty
}
}
/*
Closure examples
(6) Access by index
*/
let numbers = [15, 23, 2, 9, 16]
let reverseSorted = numbers.sorted { $0 > $1 }
/*
The value of reverseSorted:
[23, 16, 15, 9, 2]
*/