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
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
const size_t INITIAL_SIZE = 16; | |
typedef struct String | |
{ | |
size_t len; |
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
Show hidden characters
{ | |
// JSHint Default Configuration File (as on JSHint website) | |
// See http://jshint.com/docs/ for more details | |
//jshint options document: [http://jshint.com/docs/options/#strict](http://jshint.com/docs/options/#strict) | |
"maxerr" : 50, // {int} 超过{int}个错误后,停止检测错误 | |
// Enforcing | |
"bitwise" : false, // true: 禁止使用位逻辑符 (&, |, ^, ...) | |
"camelcase" : false, // true: 变量名必须是驼峰风格 |
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
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <stdio.h> | |
#include <fcntl.h> | |
int my_daemon() { | |
int maxfd, fd; |
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
import socket | |
BUF_SIZE = 4096 | |
HOST = 'httpbin.org' | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((HOST, 80)) | |
req_msg = [ | |
b'GET /ip HTTP/1.1', |
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
import fcntl | |
import time | |
pidfile = "1.pid" | |
with open(pidfile, "w") as f: | |
try: | |
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) |
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
// 牛顿法求 平方根 | |
// 如果要求s(s>1)的平方根, 选取1< X0 <s | |
// Xn+1 = (1/2) * (Xn + S / Xn) | |
const print = console.log | |
function sqrt(s) { | |
let [x0, i] = [1, 0] | |
while (i++ < 10) { | |
x = (1/2.0) * (x0 + s/x0) |
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
const request = require('request') | |
const cheerio = require('cheerio') | |
const r = request.defaults({'proxy': 'http://127.0.0.1:8087'}) | |
const URL = 'http://www.hltv.org' | |
const print = console.log | |
r(`${URL}/results/`, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
print("----------------------------------") |
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
const request = require('request'), | |
cheerio = require('cheerio'), | |
colors = require('colors') | |
const log = console.log | |
const URL = 'https://nqdeng.github.io/7-days-nodejs/' | |
request(URL, (error, response, body) => { | |
if (!error && response.statusCode == 200) { |
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
const print = console.log | |
const dns = require('dns') | |
const hostname = 'v2ex.com' | |
Promise.prototype.success = Promise.prototype.then | |
Promise.prototype.error = Promise.prototype.catch | |
function lookup(hostname) { | |
return new Promise(function (resolve, reject) { |
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 swap(A, left, right, t) { | |
t = A[left] | |
A[left] = A[right] | |
A[right] = t | |
} | |
function qsort(A, left, right, pivot, i, j) { | |
if (left < right) { | |
# select a pivot element | |
pivot = left |
NewerOlder