Skip to content

Instantly share code, notes, and snippets.

View paranoidjk's full-sized avatar

paranoidjk paranoidjk

View GitHub Profile
@paranoidjk
paranoidjk / hello.js
Created January 5, 2016 13:59
define a module which can use in Node, AMD, CMD and Browser by warp the code in a closure.
;(function (name, definition) {
// test if the context is AMD or CMD
var hasDefine = typeof define === 'function',
// test if the context is Node
hasExports = typeof module !== 'undefined' && module.exports;
if (hasDefine) {
// AMD or CMD
define(definiton);
} else if (hasExports) {
var http = require('http')
, parse = require('url').parse;
function urlget(url, callback) {
var info = parse(url)
, path = info.pathname + (info.search || '')
, options = { host: info.hostname, port: info.port || 80, path: path, method: 'GET' };
var req = null, request_timeout = null;
request_timeout = setTimeout(function() {
request_timeout = null;
req.abort();
var http = require('http')
, parse = require('url').parse;
function urlget(url, callback) {
var info = parse(url)
, path = info.pathname + (info.search || '')
, options = { host: info.hostname, port: info.port || 80, path: path, method: 'GET' };
var req = null, request_timeout = null;
request_timeout = setTimeout(function() {
request_timeout = null;
req.abort();
var parse = require('url').parse
, http = require('http')
, fs = require('fs');
function upload(url, uploadfile, callback) {
var info = parse(url)
, path = info.pathname + (info.search || '')
, options = { host: info.hostname, port: info.port || 80, path: path, method: 'POST' };
var req = http.request(options, function(res) {
var chunks = [], length = 0;
res.on('data', function(chunk) {
var parse = require('url').parse
, http = require('http')
, fs = require('fs');
function download(url, savefile, callback) {
console.log('download', url, 'to', savefile)
var urlinfo = parse(url);
var options = {
method: 'GET',
host: urlinfo.host,
path: urlinfo.pathname
@paranoidjk
paranoidjk / phpstorm.sh
Created January 11, 2016 06:18
php storm在mac上卡顿
# 用的是 mac osx,编辑 phpstorm 的启动配置文件,其他平台根据情况选择:
sudo vim /Applications/PhpStorm.app/Contents/bin/phpstorm.vmoptions
# 修改参数,根据具体需要修改即可,一般修改 -Xmx(即最大可占内存)即可
-Xms512m
-Xmx2048m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseCompressedOops
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
;(function(win, ctrl) {
var incId = 0;
function ControlName(element, options) {
var that = this;
var id = Date.now() + '-' + (++incId); // 每个控件有唯一的id
var root = document.createDocumentFragment(); // 文档片段,用于append时提高效率
if (arguments.length === 1 && !(arguments[0] instanceof HTMLElement)) {
// 参数个数的兼容判断
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta lang="zh">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="description" content="">
<meta name="keyword" content="">
<title>XXX</title>
@paranoidjk
paranoidjk / reset.css
Last active March 29, 2016 06:01
simple css reset
body{
line-height:1.4;
color:#333;
font-family:arial;
font-size: 12px;
background:white;
}
input,textarea,select{
font-size:12px;
font-size:100%;