Skip to content

Instantly share code, notes, and snippets.

☕️
<head>

Garen Yöndem garenyondem

☕️
<head>
Block or report user

Report or block garenyondem

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
View kill_long_running_procs.sh
#!/bin/bash
# Get ids of processes running longer than 6 hrs (21600 secs)
PIDS=$(ps eaxo etimes,bsdtime,pid,comm,cmd | grep node | grep command-line-processes | awk '{if ($1 >= 21600) print $3}')
for i in ${PIDS};
do {
PROC_FILE_PATH=$(ps eaxo pid,cmd | grep node | grep "$i"| awk '{print $3}');
SCRIPT_NAME=$(basename "$PROC_FILE_PATH");
printf "Killing $SCRIPT_NAME\n";
@garenyondem
garenyondem / diff.js
Created Feb 21, 2019
Diff using Lodash
View diff.js
module.exports = function difference(object, base) {
function changes(object, base) {
let arrayIndexCounter = 0;
return _.transform(object, function (result, value, key) {
if (!_.isEqual(value, base[key])) {
let resultKey = _.isArray(base) ? arrayIndexCounter++ : key;
result[resultKey] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value;
console.log("Result: " + JSON.stringify(result));
}
});
@garenyondem
garenyondem / promiseRetry.js
Last active Nov 21, 2018
Recursively retry promise function by given number of times and arguments
View promiseRetry.js
module.exports = function (func, times, ...args) {
return new Promise((resolve, reject) => {
if (times <= 0) {
return reject();
}
func.apply(this, args).then((result) => {
if (!result) {
throw new Error();
}
return resolve(result);
@garenyondem
garenyondem / specialDaysHelper.js
Created Oct 18, 2018
Mother's day & father's day helper
View specialDaysHelper.js
'use strict';
function getMothersDay(year) {
// Earliest possible Mothers day
var date = new Date(year, 4, 7);
date.setDate(7 + (7 - date.getDay()));
return date;
}
function getFathersDay(year) {
// Earliest possible Fathers day
@garenyondem
garenyondem / toWesternNumerals.js
Last active Oct 18, 2018
Convert Arabic or Persian numerals to Western numerals
View toWesternNumerals.js
String.prototype.toWesternNumerals = function () {
return this.replace(/[\u0660-\u0669]/g, (c) => {
return c.charCodeAt(0) - 0x0660;
}).replace(/[\u06f0-\u06f9]/g, (c) => {
return c.charCodeAt(0) - 0x06f0;
});
}
@garenyondem
garenyondem / qrCode.js
Last active Oct 10, 2018 — forked from sjcotto/qrCode.js
Generate QR Code and save to mongodb
View qrCode.js
'use strict';
const qr = require('qr-image');
const mongoose = require('mongoose');
const Grid = require('gridfs');
const json = {
email: 'john@doe.com',
name: 'John Doe'
};
@garenyondem
garenyondem / hashid.js
Last active Sep 30, 2018 — forked from fiznool/hashid.js
Short 'hash' ID generator.
View hashid.js
'use strict';
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+';
const ALPHABET_LENGTH = ALPHABET.length;
const ID_LENGTH = 8;
const UNIQUE_RETRIES = 9999;
let HashID = {};
HashID.generate = function () {
View randomLatLon.js
function randomLatLon() {
let lat = (Math.random() * 180 - 90).toFixed(8)
let lon = (Math.random() * 360 - 180).toFixed(8)
return {
lat,
lon
}
}
@garenyondem
garenyondem / nonce.js
Created Sep 12, 2018
Create random strings for one time usage
View nonce.js
function nonce(length) {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
module.exports = nonce;
@garenyondem
garenyondem / encryptor.js
Last active Oct 23, 2018
Encrypt or decrypt strings in Node.js
View encryptor.js
const crypto = require('crypto');
module.exports = class Encryptor {
constructor(encryptionKey) {
this.ENCRYPTION_KEY = encryptionKey.toString(); // Must be 256 bits (32 characters)
this.IV_LENGTH = 16; // For AES, this is always 16
}
encrypt(text) {
let iv = crypto.randomBytes(this.IV_LENGTH);
You can’t perform that action at this time.