Skip to content

Instantly share code, notes, and snippets.

@hsharghi
hsharghi / ArrayFunctions.mq4
Last active November 7, 2016 12:12 — forked from currencysecrets/ArrayFunctions.mq4
Array utility functions for MetaTrader 4. Helpful functions for doing some of the repetitive tasks in MQL.
/*
* 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 ); }
@hsharghi
hsharghi / countdown.js
Created January 4, 2017 13:40 — forked from adhithyan15/countdown.js
A simple countdown timer in Javascript
/********************************************************************************************************************
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 http://jsfiddle.net/HRrYG/ 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 http://jsfiddle.net/JmrQE/2/.
********************************************************************************************************************/
function countdown(minutes) {
var seconds = 60;
var mins = minutes
@hsharghi
hsharghi / Package.swift
Created May 31, 2018 10:51
Blog API using Vapor 3
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "blog",
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
// 🔵 Swift ORM (queries, models, relations, etc) built on MySQL.
@hsharghi
hsharghi / User.swift
Last active May 31, 2018 12:20
User model for Blog API
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
hsharghi / routes.swift
Last active May 31, 2018 13:37
Routes for Blog API using Vapor 3
import Vapor
public func routes(_ router: Router) throws {
try router.register(collection: UserController())
}
@hsharghi
hsharghi / routes-0.swift
Created May 31, 2018 13:54
Routes for Blog API in Vapor 3
import Vapor
public func routes(_ router: Router) throws {
let userController = UserController()
router.post("users", use: UserController.create)
router.get("users", use: UserController.index)
router.get("users", User.parameter, use: UserController.show)
router.patch("users", use: UserController.update)
router.delete("users", User.parameter, use: UserController.delete)
@hsharghi
hsharghi / UserController.swift
Created May 31, 2018 14:10
UserController-00.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
hsharghi / ValidateIranianNationalCode.swift
Last active October 22, 2018 20:48
Validate Iranian national code in Swift 4 - کنترل صحت کد ملی ایران
func validate(input: String) -> Bool {
let digits = input.map { 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
hsharghi / Post.swift
Last active December 20, 2019 19:37
virgool-blog-0005
import Vapor
import FluentMySQL // 1
final class Post: MySQLModel { // 2
var id: Int?
var title: String
var body: String // 3
init(id: Int? = nil, title: String, body: String) { // 4
self.id = id
@hsharghi
hsharghi / map.swift
Created December 13, 2019 01:00
virgool-blog-0001
let futurePosts = getPostsFromDatabase().map { posts in
// posts: [Post]
for post in posts {
print(post.title)
}
}