Skip to content

Instantly share code, notes, and snippets.

View farzadshbfn's full-sized avatar

Farzad Sharbafian farzadshbfn

View GitHub Profile
@farzadshbfn
farzadshbfn / gist:94d95c4b912baa184bef2f5965b12889
Last active April 3, 2017 14:48 — forked from ebraminio/gist:5292017
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go
// Check Iranian National Code Validity - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift3.0
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، روبی، جاوااسکریپت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست http://www.fardanews.com/fa/news/127747
/**
* @author Ebrahim Byagowi (2013-)
* @lincense: Public Domain
*/
@farzadshbfn
farzadshbfn / UserProfile_v1.swift
Last active September 14, 2018 10:19
Basic UserProfile
struct UserProfile {
let name: String
let lastName: String
let cellNumber: String
let email: String?
}
typealias Email = String
typealias CellNumber = String
struct UserProfile {
let name: String
let lastName: String
let cellNumber: CellNumber
let email: Email?
}
struct Email {
let address: String
/** Or instead of saving the address, extract it on initliazation to localPort@domain
* and generate address everytime someone tries to access it?
* the thing is, we can do that in future, without changing the public API.
*/
// let domain: String
// let localPart: String
}
struct UserProfile {
let name: String
let lastName: String
let cellNumber: String
let email: String?
}
extension UserProfile {
var fullName: String {
return name + " " + cellNumber
struct User {
let id: String
let cellNumber: String
let isRegistered: Bool
let profile: UserProfile?
}
struct UserProfile {
let name: String
let lastName: String
typealias UserId = String
struct User {
let id: UserId
let cellNumber: CellNumber
let isRegistered: Bool
let profile: UserProfile?
}
struct UserProfile {
struct User {
typealias Id = String
let id: Id
let cellNumber: CellNumber
let isRegistered: Bool
let profile: Profile?
struct Profile {
struct User {
typealias Id = String
let id: Id
let cellNumber: CellNumber
let status: Status
enum Status {
case notRegistered
// not registered user
"user": {
"id": "a_unique_id",
"cell_number": "+989354358291",
"is_registered": false
}
// registered user
"user": {
"id": "a_unique_id",
"cell_number": "+989354358291",