This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// master.js | |
'use strict'; | |
const fork = require('child_process').fork; | |
const cpus = require('os').cpus(); | |
console.log('master pid:', process.pid); | |
for (let i = 0; i < cpus.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.js | |
'use strict'; | |
const dgram = require('dgram'); | |
const server = dgram.createSocket('udp4'); | |
server.on('error', err => { | |
console.log(`server error:\n${err.stack}`); | |
server.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.js | |
'use strict'; | |
const net = require('net'); | |
const server = net.createServer(function (socket) { | |
socket.setEncoding('utf-8'); | |
// 新的连接 | |
socket.on('data', function (data) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// kill -USR2 61365 | |
const heapdump = require('heapdump'); | |
const http = require('http'); | |
const leakArray = []; | |
const leak = function () { | |
leakArray.push('leak' + Math.random()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const os = require('os'); | |
function format (bytes) { | |
return (bytes / 1024 / 1024).toFixed(2) + ' MB'; | |
} | |
function showMem () { | |
const mem = process.memoryUsage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const http = require('http'); | |
const server = http.createServer((req, res) => { | |
console.log(req.url); | |
res.end('simple server'); | |
}); | |
server.on('error', err => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fibonacci(n) { | |
if (n == 0 || n == 1) return n; | |
return fibonacci(n - 1) + fibonacci(n - 2); | |
} | |
const now = Date.now(); | |
const i = fibonacci(40); | |
console.log(i); | |
console.log(String(Date.now() - now), 'ms'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import os | |
root_dir = os.getcwd() | |
names = ["js"] | |
def list_code(dir): | |
for lists in os.listdir(dir): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "fileutils" | |
# 循环文件夹的块包装 | |
def each_dir(dirname) | |
Dir.open(dirname) do |dir| | |
dir.each do |name| | |
next if name == "." | |
next if name == ".." | |
yield name | |
end |