This file contains hidden or 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 | |
name = socket.gethostname() | |
ip_addr = socket.gethostbyname(name) | |
print name | |
print ip_addr |
This file contains hidden or 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
/**//**//**//**//**//**//* | |
** ================================================================================================== | |
** 类名:J.gbk | |
** 版本:1.0 | |
** 功能:URLEncode,URLDecode | |
** 示例: | |
--------------------------------------------------------------------------------------------------- | |
用法:参见组件地址 | |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# | |
# Author: oldj | |
# Email: [email protected] | |
# Blog: http://oldj.net | |
# | |
import os | |
import re | |
import StringIO |
This file contains hidden or 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
def bigFileView(request): | |
u"""在Django中提供大内容(或大文件)下载 | |
@see http://oldj.net/article/django-big-file-response/ | |
""" | |
# do something... | |
def readFile(fn, buf_size=262144): | |
f = open(fn, "rb") | |
while True: | |
c = f.read(buf_size) |
This file contains hidden or 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 左边截取n个字符 | |
* 如果包含汉字,则汉字按两个字符计算 | |
* @see http://oldj.net/article/javascript-left-n-characters/ | |
* @param s {String} 输入的字符串 | |
* @param n {Number} | |
*/ | |
function strLeft(s, n) { | |
var s2 = s.slice(0, n), | |
i = s2.replace(/[^\x00-\xff]/g, "**").length; |
This file contains hidden or 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
#!/bin/bash | |
# Interactive PoPToP install script for an OpenVZ VPS | |
# Tested on Debian 5, 6, and Ubuntu 11.04 | |
# April 2, 2013 v1.11 | |
# http://www.putdispenserhere.com/pptp-debian-ubuntu-openvz-setup-script/ | |
echo "######################################################" | |
echo "Interactive PoPToP Install Script for an OpenVZ VPS" | |
echo | |
echo "Make sure to contact your provider and have them enable" |
This file contains hidden or 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
/** | |
* goto URL without losting refer | |
* @see http://oldj.net/article/referrer-by-location-href-in-ie/ | |
*/ | |
function gotoUrl(url) { | |
if (!document.attachEvent) { | |
//define for none-IE browsers | |
location.href = url; | |
} else { | |
//define for IE |
This file contains hidden or 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
tell application "Path Finder" | |
set theSelection to the selection | |
if theSelection is equal to missing value or the (count of items in theSelection) is 0 then | |
set theSelection to the name of the front window | |
return theSelection | |
else | |
return path of (item 1 of theSelection) | |
end if | |
end tell |
This file contains hidden or 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
new Array(10) | |
.fill(0).map((_, i) => i) | |
.reduce((p, c, i) => p * (i + 1), 1); // 3628800 |
This file contains hidden or 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 bash | |
f=type_tmp | |
if [ ! -d ${f} ] | |
then | |
mkdir ${f} | |
fi | |
cd ${f} | |
if [ ! -f wkhtmltopdf ] |
OlderNewer