Skip to content

Instantly share code, notes, and snippets.

@StarpTech
StarpTech / event-loop-examples.js
Created May 23, 2017 10:05
Great examples to understand the differences of setImmediate, setTimeout and nextTick()
/**
* setImmediate callbacks are fired off the event loop, once per iteration in the order that they were queued.
* So on the first iteration of the event loop, callback A is fired.
* Then on the second iteration of the event loop, callback B is fired, then on the third iteration of the event loop callback C is fired, etc.
* This prevents the event loop from being blocked and allows other I/O or timer callbacks to be called in the mean time (as is the case of the 0ms timeout, which is fired on the 1st or 2nd loop iteration).
*/
setImmediate(function A() {
setImmediate(function B() {
console.log(1);
@TastyToast
TastyToast / youtube-api-helper.js
Created September 4, 2013 00:32
YouTube JS API Helper
/**
* @author Rob W <gwnRob@gmail.com>
* @website http://stackoverflow.com/a/7513356/938089
* @version 20120724
* @description Executes function on a framed YouTube video (see website link)
* For a full list of possible functions, see:
* https://developers.google.com/youtube/js_api_reference
* @param String frame_id The id of (the div containing) the frame
* @param String func Desired function to call, eg. "playVideo"
* (Function) Function to call when the player is ready.
var keepsHisWord;
keepsHisWord = true;
promise1 = new Promise(function(resolve, reject) {
if (keepsHisWord) {
resolve("The man likes to keep his word");
} else {
reject("The man doesnt want to keep his word");
}
});
console.log(promise1);
@ewencp
ewencp / ela.py
Created August 15, 2012 05:52
Quick, simple implementation of Error Level Analysis
#!/usr/bin/env python
# This is a really simple implementation of ELA as described in
# http://blackhat.com/presentations/bh-dc-08/Krawetz/Whitepaper/bh-dc-08-krawetz-WP.pdf
# You shouldn't actually use it, or at least read the paper carefully
# and implement more of the techniques before drawing any conclusions.
from PIL import Image, ImageChops, ImageEnhance
import sys, os.path
const deepCopyFunction = (inObject) => {
let outObject, value, key
if (typeof inObject !== "object" || inObject === null) {
return inObject // Return the value if inObject is not an object
}
// Create an array or object to hold the values
outObject = Array.isArray(inObject) ? [] : {}
let bookmarkList = Array.from(document.querySelectorAll('.widget>.vbox'))
.map(e => e.shadowRoot)
.map(e => e && e.querySelector('.device-page-list'))
.find(e => e);
let bookmarks = Array.from(bookmarkList.querySelectorAll('.vbox'))
.map(e => `<a href="${e.querySelector('x-link').innerHTML}">${e.querySelector('.device-page-title').innerHTML}</a>`);
copy('<html><body>' + bookmarks.join('\n') + '</body></html>');
@rjoydip-zz
rjoydip-zz / UV_THREADPOOL_SIZE.md
Last active January 5, 2024 13:08
How you can set `UV_THREADPOOL_SIZE` value?

When you need to set value to "UV_THREADPOOL_SIZE"?

  • Libuv has a default thread pool size of 4, and uses a queue to manage access to the thread pool - the upshot is that if you have 5 long-running DB queries all going at the same time, one of them (and any other asynchronous action that relies on the thread pool) will be waiting for those queries to finish before they even get started.

  • Note, however, that tuning UV_THREADPOOL_SIZE may make more sense for a standalone application like a CLI written in Node.js. If you are standing up a bunch of Node.js processes using the cluster module then I would be surprised if tuning UV_THREADPOOL_SIZE was particularly beneficial for you. But if your application resembles the web tooling benchmarks then tuning UV_THREADPOOL_SIZE may help with performance.

@esedic
esedic / detect_touch.js
Created September 6, 2019 11:34
Various JavaScript methods for detecting touch/mobile devices
// Method 1
var isTouchDevice =
(('ontouchstart' in window) ||
(navigator.MaxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0));
if(!isTouchDevice){
console.log('is not touch');
}else{
console.log('is touch');
}
@ummahusla
ummahusla / git-overwrite-branch.sh
Last active February 25, 2024 00:06 — forked from brev/git-overwrite-branch.sh
Git overwrite branch with another branch
# overwrite master with contents of feature branch (feature > master)
git checkout feature # source name
git merge -s ours master # target name
git checkout master # target name
git merge feature # source name
@ncreated
ncreated / PrintLocalesController.m
Last active February 29, 2024 16:29
List of iOS locales with currency formatting.
//
// PrintLocalesController.m
// NSFormatterTest
//
// Created by Maciek Grzybowski on 02.04.2014.
//
#import "PrintLocalesController.h"
@interface PrintLocalesController ()