Skip to content

Instantly share code, notes, and snippets.

View kukiron's full-sized avatar
🛠️
Still enjoying the craft.

Kafil Uddin Kiron kukiron

🛠️
Still enjoying the craft.
View GitHub Profile
@kukiron
kukiron / ConEmu.xml
Last active June 24, 2018 10:07
Customizing Cmder
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2018-06-23 05:35:48" build="161206">
<value name="ColorTable00" type="dword" data="00191919"/>
<value name="ColorTable01" type="dword" data="00ee0000"/>
<value name="ColorTable02" type="dword" data="0000cd00"/>
<value name="ColorTable03" type="dword" data="00cdcd00"/>
<value name="ColorTable04" type="dword" data="000000cd"/>
<value name="ColorTable05" type="dword" data="00cd00cd"/>
@kukiron
kukiron / code.settings.json
Last active July 6, 2018 02:32
VSCodeSettings for Angular Projects
{
"auto-rename-tag.activationOnLanguage": [
"html",
"xml",
"php",
"javascript",
"javascriptreact"
],
/** BEAUTIFY **/
"beautify.language": {
@kukiron
kukiron / OneDark+
Last active May 21, 2018 05:16
Customized OneDark+ Sublime Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>One Dark+</string>
<key>author</key>
<string>Josh Peng</string>
<key>settings</key>
<array>
@kukiron
kukiron / main.js
Last active April 28, 2018 14:52
Scripts for Screeps - Latest progress
/* eslint indent: [ "error", 4 ], no-undef: 0 */
const roleHarvester = require("role.harvester")
const roleUpgrader = require("role.upgrader")
const roleBuilder = require("role.builder")
// _.sum will count the number of creeps for each role
const countCreeps = creepRole =>
_.sum(Game.creeps, c => c.memory.role == creepRole)
module.exports.loop = () => {
@kukiron
kukiron / after_res_hooks.js
Created March 2, 2018 13:06 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups
@kukiron
kukiron / promise-observe.js
Last active February 24, 2018 22:51
Observe the completions of Promises without interfering with them
if (!Promise.observe) {
Promise.observe = function(pr, cb) {
pr.then(function fullfilled(msg) {
Promise.resolve(msg).then(cb)
}, function rejected(err) {
Promise.reject(err).then(cb)
})
return pr
}
@kukiron
kukiron / timeoutPromise.js
Last active February 24, 2018 21:54
Function for checking whether setTimeout occurs for a network call
function timeoutPromise(ms, promise) {
return new Promise((resolve, reject) => {
const timeoutID = setTimeout(() => {
reject(new Error("TIMEOUT!!"))
}, ms)
promise.then(res => {
clearTimeout(timeoutID)
resolve(res)
}, err => {
@kukiron
kukiron / es7-async-await.js
Created February 24, 2018 18:47
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@kukiron
kukiron / promises.md
Created February 24, 2018 12:58 — forked from domenic/promises.md
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
/** Question 1 **/
// Factory function to create the counter object
const myCounter = (count = 0) => ({
getState: () => count,
inc: () => ++count,
dec: () => --count
})
const counter = myCounter()