Skip to content

Instantly share code, notes, and snippets.

View furixturi's full-sized avatar
😈

Xiaoli Shen furixturi

😈
View GitHub Profile
let ary = [0, 1, 2, 3, 4]
// closed range operator
for i in 0...3 {
print(ary[i])
}
/*
0
1
2
3
// Variant A, the innocent one
var n = 2
while n < 100 {
n *= 2
}
/* at last, n is 128 */
// Variant B, use "repeat" to make sure it is executed at least once
var m = 2
repeat {
// Loop a dictionary
let superheroes = [
"Captain America": "Steve Rogers",
"Iron Man": "Tony Stark",
"Black Widow": "Natasha Romanova"
]
for (key, value) in superheroes {
print("\(key): \(value)")
}
/*
let apples = 3 // Interpreted as an Int
let oranges = 5 // Intepreted as an Int
print(apples/oranges) // 0
// Array instantiation
var myArray = [String]()
myArray.append("Me")
myArray.append("You")
print(myArray[1]) //You
// Dictionary instantiation
var myDictionary = [String: Float]()
myDictionary["ha"] = 1
print(myDictionary) //["ha" : 1.0]
let numOfApples = 3
print("I have \(numOfApples) apples")
let aConstant: Int = 70
var aVariable: Int = 70
aConstant += 1 // Error! aConstant is not mutable
aVariable += 1
@furixturi
furixturi / wp-without-ftp.php
Created September 10, 2017 13:08
add a wordpress template file without using ftp
/* in header.php */
<?php touch('wp-content/themes/{your theme name}/{your template name}.php'); ?>
@furixturi
furixturi / shuffleAry.js
Created July 31, 2017 23:48
Fischer-Yates shuffle an array
function shuffleArray(ary) {
var i = ary.length, j, x;
while (i) {
j = Math.floor(Math.random() * i);
i -= 1;
x = ary[i];
ary[i] = ary[j];
ary[j] = x;
}
}
@furixturi
furixturi / gist:7413927
Created November 11, 2013 14:27
JS stack trace
var err = new Error();
console.log(err.stack)