Skip to content

Instantly share code, notes, and snippets.

Hadi Sharghi hsharghi

Block or report user

Report or block hsharghi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
hsharghi / ValidateIranianNationalCode.swift
Last active Oct 22, 2018
Validate Iranian national code in Swift 4 - کنترل صحت کد ملی ایران
View ValidateIranianNationalCode.swift
func validate(input: String) -> Bool {
let digits = { Int(String($0)) }
guard digits.count == 10 && digits.count == input.count else {
return false
let check = digits[9]!
let remainder = digits.prefix(upTo: 9).enumerated().reduce(0) {
hsharghi / UserController.swift
Created May 31, 2018
View UserController.swift
import Vapor
import Crypto // 1
/// Controls basic CRUD operations on `User`s.
final class UserController: RouteCollection {
func boot(router: Router) throws {
let users = router.grouped("users") // 2
users.get(use: index)
hsharghi / routes-0.swift
Created May 31, 2018
Routes for Blog API in Vapor 3
View routes-0.swift
import Vapor
public func routes(_ router: Router) throws {
let userController = UserController()"users", use: UserController.create)
router.get("users", use: UserController.index)
router.get("users", User.parameter, use:
router.patch("users", use: UserController.update)
router.delete("users", User.parameter, use: UserController.delete)
hsharghi / routes.swift
Last active May 31, 2018
Routes for Blog API using Vapor 3
View routes.swift
import Vapor
public func routes(_ router: Router) throws {
try router.register(collection: UserController())
hsharghi / User.swift
Last active May 31, 2018
User model for Blog API
View User.swift
import FluentMySQL
import Vapor
final class User: MySQLModel { // 1
/// The unique identifier for `User` // 2
var id: Int?
// Additional properties of `User` // 3
var email: String
var password: String
hsharghi / Package.swift
Created May 31, 2018
Blog API using Vapor 3
View Package.swift
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "blog",
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "", from: "3.0.0"),
// 🔵 Swift ORM (queries, models, relations, etc) built on MySQL.
hsharghi / countdown.js
Created Jan 4, 2017 — forked from adhithyan15/countdown.js
A simple countdown timer in Javascript
View countdown.js
Countdown.js is a simple script to add a countdown timer
for your website. Currently it can only do full minutes
and partial minutes aren't supported. This script is a fork of with some
added extensions. Since the original code that I forked was released under Creative Commons by SA license,
I have to release this code under the same license. You can view a live demo of this code at
function countdown(minutes) {
var seconds = 60;
var mins = minutes
hsharghi / ArrayFunctions.mq4
Last active Nov 7, 2016 — forked from currencysecrets/ArrayFunctions.mq4
Array utility functions for MetaTrader 4. Helpful functions for doing some of the repetitive tasks in MQL.
View ArrayFunctions.mq4
* clearIntArray
* This function deletes all items in array (sets it to 0) and resizes array according to size (default = 1).
* @param int& theArray - passing the array by reference
* @param int size - size of the array (default = 1)
* @return int blank array of size
int clearIntArray( int& theArray[], int size = 0 ) {
ArrayResize( theArray, size );
if ( size > 0 ) { ArrayInitialize( theArray, 0 ); }
You can’t perform that action at this time.