Skip to content

Instantly share code, notes, and snippets.

View oldj's full-sized avatar
👨‍🚀
:-o

oldj oldj

👨‍🚀
:-o
View GitHub Profile
@oldj
oldj / big_file_download.py
Last active August 29, 2015 14:12
在Django中提供大内容(或大文件)下载
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)
@oldj
oldj / left_n.js
Last active August 29, 2015 14:12
从字符串左边截取n个字符
/**
* 从字符串 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;
@oldj
oldj / ezpptp.sh
Created January 6, 2015 06:34
ezpptp.sh
#!/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"
@oldj
oldj / goto_url.js
Last active August 29, 2015 14:12
转到指定URL,同时不丢失refer
/**
* 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
@oldj
oldj / get_ip_address.py
Created January 6, 2015 03:14
取得IP地址及主机名
import socket
name = socket.gethostname()
ip_addr = socket.gethostbyname(name)
print name
print ip_addr
#!/usr/bin/env bash
f=type_tmp
if [ ! -d ${f} ]
then
mkdir ${f}
fi
cd ${f}
if [ ! -f wkhtmltopdf ]
@oldj
oldj / fontlist.m
Last active February 6, 2017 05:56
macOS 输出系统支持的所有字体
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"%@", [[[NSFontManager sharedFontManager] availableFontFamilies] description]);
}
return 0;
}
@oldj
oldj / t.js
Last active April 10, 2017 06:46
计算阶乘
new Array(10)
.fill(0).map((_, i) => i)
.reduce((p, c, i) => p * (i + 1), 1); // 3628800
{"sig":"3e15fb07411f50009cfdf0ab530068b47a070dbfbc4a3c5462f69a0e9978c27c621316922aa6f2a5f928060612c8d41510da61b85e87549b098ec9aedd80432f0","msghash":"028aef50a39656cea5710bc21835bd08a8e180965609553130a305174fd33e30"}
@oldj
oldj / maze.p8
Created June 1, 2019 09:51
PICO-8
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- maze
_tt = 0
grids = {}
grid_size = 6
maze_width = 18
maze_height = 18