Skip to content

Instantly share code, notes, and snippets.

struct Person {
let firstName: String
let middleName: String?
let lastName: String
func getFullName() -> String {
if middleName == nil {
return firstName + " " + lastName
} else {
return firstName + " " + middleName! + " " + lastName
let week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
func weekdayOrWeekend(day: String) -> String {
switch day {
case "Saturday", "Sunday": return "Weekend"
case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday": return "Weekday"
default: return "This isn't a valid day in the Western calendar"
}
}
@thanhluu
thanhluu / Bai Tap Struct.swift
Created April 29, 2016 14:14
Bai Tap Struct
struct User {
var fullName: String
var email: String
var age: Int
}
var someUser = User(fullName: "Thanh Luu", email: "[email protected]", age: 27)
var anotherUser = someUser
@thanhluu
thanhluu / Bai Tap Class.swift
Created April 29, 2016 14:13
Bai Tap Class
class Point {
var x: Int
var y: Int
init(x: Int, y: Int){
self.x = x
self.y = y
}
}
@thanhluu
thanhluu / Swift Struct & Class.swift
Created April 29, 2016 14:13
Swift Struct & Class
let x1 = 0
let y1 = 0
let coordinate1: (x: Int, y: Int) = (0,0)
coordinate1.x
struct Point {
let x: Int
let y: Int
@thanhluu
thanhluu / Swift Function.swift
Created April 29, 2016 14:11
Swift Function
// Swift Functions
func calculateArea(length: Int, width: Int) -> Int {
let area = length * width
return area
}
// Room 1
let areaOfRoom1 = calculateArea(10, width: 8)
@thanhluu
thanhluu / Swift Variables and Constants.swift
Last active April 29, 2016 14:11
Swift Variables and Constants
let favoriteProgramingLanguage = "Swift"
let year = 2014 // Int
var version = 2.0 // Double
var isAwesome = true // Bool
var someString = ""
@thanhluu
thanhluu / my.cnf
Created February 15, 2016 14:29
Best MySQL Configuration (/etc/my.cnf) for 2GB RAM VPS
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
@thanhluu
thanhluu / style.css
Last active February 16, 2016 04:50
Show status of questions like DW Question & Answer 1.3
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
.dwqa-questions-list .dwqa-question-item {
padding-left: 70px;
}
.dwqa-questions-list .dwqa-question-item .avatar {
position: static;
width: 12px;
height: 12px;
@thanhluu
thanhluu / checkbase.php
Last active October 26, 2017 11:53
Ignore folder for theme check
// Search "$dir_iterator" then insert those codes below this line:
// $dir_iterator = new RecursiveDirectoryIterator( $dir );
$filter = array( 'framework', 'tools', 'vendor', 'lib', 'installer', 'updater' );
$dir_iterator = new \RecursiveCallbackFilterIterator(
$dir_iterator,
function( $item ) use ( $filter ) {
return ! in_array( $item->getBaseName(), $filter );
}
);