Skip to content

Instantly share code, notes, and snippets.

View munkhorgil's full-sized avatar
🎯
Focusing

Orgil munkhorgil

🎯
Focusing
View GitHub Profile
Hiking ████████████████░░░░ 82% 🏔
Walking █████████████████░░░ 89% 🚶‍
Cycling ██████████████░░░░░░ 78% 🚴‍
@munkhorgil
munkhorgil / Skills
Last active April 12, 2022 13:38
Orgil's Coding skills
Vim ██████████████████░░ 95%
JS █████████████████░░░ 90%
GraphQL ████████████████░░░░ 89%
MongoDB ████████████████░░░░ 89%
Rust ██░░░░░░░░░░░░░░░░░░ 5%
@munkhorgil
munkhorgil / app.js
Last active May 22, 2020 06:38
Wait cronjob to finish when node app received the SIGINT signal
/**
* Description: Wait until cron jobs finish when node app received the SIGINT signal
* scripts: "dev": "DEBUG=Goblin:* pm2 start --kill_timeout 300000 app.js"
* Author: Munkh-Orgil
* Date: 22/05/2020
*/
const express = require('express')
const events = require('events');
const http = require('http')
const debug = require('debug');
@munkhorgil
munkhorgil / jsonParseObject.js
Created April 16, 2020 07:57
JSON.parse() wrap object
const obj = {
toString() {
return "[1,2,3]";
}
};
console.log(JSON.parse(obj));
// (3) [1, 2, 3]
@munkhorgil
munkhorgil / App.js
Last active June 9, 2020 15:17
React Native handling multiple textInputs
/**
* React Native - Handling multiple TextInputs
* ---------------
* [1] [2] [3] [4]
* ---------------
* Author: Munkh-Orgil
* Date: 01/21/2020
*/
import React from 'react';
import { View, TextInput } from 'react-native';
@munkhorgil
munkhorgil / removeAllDb.js
Created October 11, 2019 07:03
Remove all mongo dbs except local, admin
// Remove all databases, except local, admin
// on command line: mongo filename.js
const dbs = db.getMongo().getDBNames()
for(var i in dbs){
db = db.getMongo().getDB( dbs[i] );
if (db.getName() !== 'admin' && db.getName() !== 'local')
{
print( "dropping db " + db.getName() );
db.dropDatabase();
@munkhorgil
munkhorgil / curriedFunction.js
Created October 10, 2019 15:48
Curried function
/*
* Compose curried function
*/
const sum = a => b => a + b;
sum(5)(15); // 20
@munkhorgil
munkhorgil / browserNote.html
Last active November 1, 2019 04:55
One line browser editor/note
data:text/html;charset=utf-8,<title>In browser editor</title><style>body{background:lightgray;black:white;padding: 100px;font-family:JMH Typewriter, serif;font-size:2rem}</style><body contenteditable onkeypress="myFunction()"><audio id="audio" src="https://www.soundjay.com/communication/sounds/typewriter-line-break-1.mp3" ></audio>
Typwriter <script>function myFunction() {var audio = document.getElementById("audio");audio.play();}</script></body>
@munkhorgil
munkhorgil / clearMongoDb.js
Last active October 10, 2019 15:33
Invoke mongodb commands from js file
(function() {
connection = new Mongo();
db = connection.getDB('your_database');
// any mongo command with client
db.dropDatabase();
})();
@munkhorgil
munkhorgil / composeAsync.js
Created October 3, 2019 08:28
Compose async functions right to left
/**
* Compose async functions
* @param {Functions} fns
* @returns {Promise} fns value
*/
const compose = (...fns) => arg => fns.reduceRight((p, f) => p.then(f), Promise.resolve(arg));
const foo = a => a + 1;
const bar = b => b + 1;