This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
if textField == cellPhoneTextField { | |
let newString = (textField.text! as NSString).replacingCharacters(in: range, with: string) | |
let components = (newString as NSString).components(separatedBy: NSCharacterSet.decimalDigits.inverted) | |
let decimalString = components.joined(separator: "") as NSString | |
let length = decimalString.length | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const spawn = require('child_process').spawn; // child_process spawn function | |
const app = require('express')(); // new express http server | |
app.use('/', (req, res) => { | |
const ls = spawn('ls', ['-lh', '/usr']); // here would be the mysqldump command | |
ls.stdout.pipe(res); | |
}); // piping the stdout (the output from the mysqldump command, in this case the ls command) to the response object | |
// using fs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const moment = require('moment'); | |
const { CronJob } = require('cron'); | |
function callback (job) { | |
} | |
exports.callback = function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Foundation | |
class GradientView: UIView, Gradientable {} | |
protocol Gradientable: class {} | |
extension Gradientable where Self: UIView { | |
private func getCGPoints (for position: GradientPosition, start at: StartAt) -> (CGPoint, CGPoint)? { | |
switch position{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Extensions.swift | |
// Swift 3 compatible | |
// | |
// Created by Quaggie. | |
// Copyright © 2017 Quaggie. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function diffArray(arr1, arr2) { | |
var arr1Diff = arr1.filter( i => arr2.filter( y => i === y).length === 0); | |
var arr2Diff = arr2.filter( i => arr1.filter( y => i === y).length === 0); | |
return arr2Diff.concat(arr1Diff); | |
} | |
console.log(diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.concatAll = function() { | |
var results = []; | |
this.forEach(function(subArray) { | |
results.push.apply(results, subArray); | |
}); | |
return results; | |
}; | |
Array.prototype.concatMap = function(fn) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Adds zeros to the beginning of the cnpj in case of database deletion | |
*/ | |
function verifyCnpj (cnpj) { | |
var strCnpj = cnpj.toString(); | |
if (cnpj.length === 14) return strCnpj; | |
if (strCnpj.length < 14) { | |
return verifyCnpj("0" + strCnpj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function factorialize(num) { | |
if (num === 1 || num === 0) return 1; | |
else if (num === 2) return 2; | |
else if (num > 2) { | |
return num * factorialize(num-1); | |
} | |
} | |
factorialize(5); |
NewerOlder