Skip to content

Instantly share code, notes, and snippets.

View pradeep1991singh's full-sized avatar
🏠
Working from home

pradeep singh pradeep1991singh

🏠
Working from home
View GitHub Profile
@vkarpov15
vkarpov15 / promise2.js
Created April 5, 2018 13:57
Write Your Own Node.js Promise Library from Scratch, Part 2
class MyPromise {
constructor(executor) {
if (typeof executor !== 'function') {
throw new Error('Executor must be a function');
}
// Internal state. `$state` is the state of the promise, and `$chained` is
// an array of the functions we need to call once this promise is settled.
this.$state = 'PENDING';
this.$chained = [];
@vkarpov15
vkarpov15 / promise1.js
Created April 5, 2018 12:38
Write Your Own Node.js Promise Library from Scratch, Part 1
class MyPromise {
constructor(executor) {
if (typeof executor !== 'function') {
throw new Error('Executor must be a function');
}
// Internal state. `$state` is the state of the promise, and `$chained` is
// an array of the functions we need to call once this promise is settled.
this.$state = 'PENDING';
this.$chained = [];
@treyhuffine
treyhuffine / PromiseSimpleExample.js
Last active March 27, 2021 19:44
An example using a simple promise implementation
class PromiseSimple {
constructor(executionFunction) {
this.promiseChain = [];
this.handleError = () => {};
this.onResolve = this.onResolve.bind(this);
this.onReject = this.onReject.bind(this);
executionFunction(this.onResolve, this.onReject);
}
@dreamsparkx
dreamsparkx / More-links.txt
Last active July 22, 2024 17:46
Install Apache, PHP, MySQL and phpMyAdmin on Mac OS X
@pradeep1991singh
pradeep1991singh / docker-delete-all.sh
Last active December 22, 2016 18:21
Docker: Remove all containers and images
#credit: https://github.com/crosbymichael
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@akirattii
akirattii / background.js
Created December 2, 2016 03:45
Message passing of Chrome Extension example
/*****************************************************************
* onMessage from the extension or tab (a content script)
*****************************************************************/
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.cmd == "any command") {
sendResponse({ result: "any response from background" });
} else {
sendResponse({ result: "error", message: `Invalid 'cmd'` });
}
@cipri7329
cipri7329 / BinaryLongestZeroSequence.java
Created July 28, 2016 11:44
Find longest sequence of zeros in binary representation of an integer.
/**
*
Find longest sequence of zeros in binary representation of an integer.
*/
public class BinaryLongestZeroSequence {
/**
* worst-case time complexity is O(log(N));
* number of bits = log(N) ==> worst case is O(N)
* @param N
@jaredpalmer
jaredpalmer / tweet.js
Created April 6, 2016 22:45
send-tweet.js
/*
* Code snippet for posting tweets to your own twitter account from node.js.
* You must first create an app through twitter, grab the apps key/secret,
* and generate your access token/secret (should be same page that you get the
* app key/secret).
* Uses oauth package found below:
* https://github.com/ciaranj/node-oauth
* npm install oauth
* For additional usage beyond status updates, refer to twitter api
* https://dev.twitter.com/docs/api/1.1
@parmentf
parmentf / GitCommitEmoji.md
Last active July 26, 2024 15:56
Git Commit message Emoji
@jaawerth
jaawerth / compose.es6.js
Last active October 17, 2020 08:08
ES5 and ES6 implementations of compose - readable implementation, not optimized
function compose(...fnArgs) {
const [first, ...funcs] = fnArgs.reverse();
return function(...args) {
return funcs.reduce((res, fn) => fn(res), first(...args));
};
}