Skip to content

Instantly share code, notes, and snippets.

@Samjin
Samjin / express4-response-methods.js
Last active October 6, 2022 07:02 — forked from prof3ssorSt3v3/app.js
Express Sending Responses of various types from YouTube tutorial.
"use strict";
// https://expressjs.com/en/4x/api.html#res
const express = require("express");
const app = express();
const port = process.env.port || 3000;
app.set("view engine", "pug");
app.set("views", process.cwd() + "/views");
app.get("/", (req, res) => {
//handle route: get requests for "/"
const dns = require('dns');
const http = require('http');
const https = require('https');
const tls = require('tls');
const net = require('net');
const request = require('request');
const httpAgent = new http.Agent();
const httpsAgent = new https.Agent();
@Samjin
Samjin / headers-timeout-keep-alive.js
Created December 15, 2021 17:28 — forked from shuhei/headers-timeout-keep-alive.js
A test case for server.headersTimeout + keep alive (fails on Node v10.15.2 and newer)
const http = require("http");
const net = require("net");
const server = http.createServer((req, res) => {
req.resume();
res.end("hello");
});
server.keepAliveTimeout = 6 * 1000;
server.headersTimeout = 4 * 1000;
@Samjin
Samjin / UV_THREADPOOL_SIZE.md
Created September 2, 2021 22:11 — forked from rjoydip-zz/UV_THREADPOOL_SIZE.md
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.

@Samjin
Samjin / multiple_ssh_setting.md
Created April 6, 2017 07:22 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"
@Samjin
Samjin / mysql import data
Created March 21, 2017 23:18
mysql import data
mysql -u root -p epg < epg.sql
@Samjin
Samjin / Rem vs Em
Created July 31, 2016 01:11
Rem vs Em
http://webdesign.tutsplus.com/tutorials/comprehensive-guide-when-to-use-em-vs-rem--cms-23984
rem and em units are computed into pixel values by the browser, based on font sizes in your design.
em units are based on the font size of the element they’re used on.
rem units are based on the font size of the html element.
em units can be influenced by font size inheritance from any parent element
rem units can be influenced by font size inheritance from browser font settings.
Use em units for sizing that should scale depending on the font size of an element other than the root.
Use rem units for sizing that doesn’t need em units, and that should scale depending on browser font size settings.
@Samjin
Samjin / Facade example
Created May 3, 2016 18:01
Facade simple exmaple
var module = (function() {
var _private = {
i:5,
get : function() {
console.log( "current value:" + this.i);
},
set : function( val ) {
this.i = val;
},
@Samjin
Samjin / Constructor and prototypeFactory
Last active July 10, 2023 04:51
Constructor and prototypeFactory
class Car {
constructor(options) {
this.doors = options.doors || 4;
this.state = options.state || "brand new";
this.color = options.color || "silver";
}
}
class Truck {
constructor(options) {
@Samjin
Samjin / Scroll() event optimization
Last active July 5, 2016 06:34
Scroll() event optimization
var throttle = (function () {
return function (fn, delay) {
delay || (delay = 100);
var last = +new Date;
return function () {
var now = +new Date;
if (now - last > delay) {
fn.apply(this, arguments);
last = now;
}