Skip to content

Instantly share code, notes, and snippets.

--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@garylgh
garylgh / py_transaction_decorator
Created May 5, 2016 07:17
Python事务装饰器
# -*- coding: utf-8 -*-
def transactional():
def transaction(func):
def __decorator(obj,*args,**kwargs):
try:
func(obj,*args,**kwargs)
print 'do commit'
obj.session.commit()
except Exception,e:
obj.session.rollback()
@garylgh
garylgh / install-npm3
Created April 28, 2016 07:45
安装npm v3版本
npm install npm@3 -g
@garylgh
garylgh / README.md
Created April 20, 2016 07:55 — forked from jimothyGator/README.md
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/
@garylgh
garylgh / gist:c6aac8df0250c8d01672
Created March 9, 2016 14:54 — forked from saidimu/gist:1024207
Generating URLs to crawl from outside a Scrapy spider
from scrapy import log
from scrapy.item import Item
from scrapy.http import Request
from scrapy.contrib.spiders import XMLFeedSpider
def NextURL():
"""
Generate a list of URLs to crawl. You can query a database or come up with some other means
Note that if you generate URLs to crawl from a scraped URL then you're better of using a
var Util = require('util');
var Https = require('https');
var Tls = require('tls');
/**
* HTTPS Agent for node.js HTTPS requests via a proxy.
* blog.vanamco.com/connecting-via-proxy-node-js/
*/
function HttpsProxyAgent(options)
{
@garylgh
garylgh / http-proxy-demo.js
Created February 29, 2016 08:56
A http proxy with nodejs
var http = require(‘http’);
var proxy = http.createServer(function(request, response) {
var options = {
host: 'proxy.xxxx.com', // 这里是代理服务器
port: 8080, // 这里是代理服务器端口
path: request.url,
method: request.method,
headers: {
@garylgh
garylgh / README.md
Created February 25, 2016 08:22 — forked from balupton/README.md
Node.js Best Practice Exception Handling
@garylgh
garylgh / gist:2a27ccac063088133030
Last active December 31, 2015 07:50
javascript format date
function formatDate(date, format) {
if (typeof date === "string") {
var mts = date.match(/(\/Date\((\d+)\)\/)/);
if (mts && mts.length >= 3) {
date = parseInt(mts[2]);
}
}
date = new Date(date);
if (!date || date.toUTCString() == "Invalid Date") {
@garylgh
garylgh / ajax_setup.js
Created December 15, 2015 07:49 — forked from alanhamlett/ajax_setup.js
Sets the X-CSRFToken header for every jQuery ajax non-GET request to make CSRF protection easy. This fixes the example from Django docs here: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (settings.type == 'POST' || settings.type == 'PUT' || settings.type == 'DELETE') {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?