Skip to content

Instantly share code, notes, and snippets.

View foxwoods's full-sized avatar

Wang Jingyu foxwoods

View GitHub Profile
@foxwoods
foxwoods / attachment-headers.php
Last active January 1, 2016 13:19
通过设置正确的HTTP header,解决下载文件时Unicode文件名乱码的问题。Set proper header to make Unicode filename works in major browsers.
<?php
//
// Set proper header to make Unicode filename works in major browsers.
// see http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http
//
$filename = '一个文件.txt';
$ua = $_SERVER["HTTP_USER_AGENT"];
<?php
class ASDF{
private static $r = 10000000;
private static $d = 10001;
private static $f = 0;
public static function encode($x) {
$x %= (self::$r - self::$r % self::$d);
return floor(self::$r / self::$d) * (($x + self::$f) % self::$d) + floor($x / self::$d);
}
@foxwoods
foxwoods / parse_csv.php
Created February 16, 2012 04:51
A PHP function to parse CSV file into big array. The 3rd parameter accepts an array of column names.
<?php
/**
* parse_csv
* parse CSV file into big array
*
* @param string $file
* @param string $separator
* @param array $meta
* @return array
@foxwoods
foxwoods / validate_rid.js
Created February 13, 2012 15:56
身份证号验证函数 | Validation function for Chinese I.D. card number
function validate_rid(id) {
// 18位身份证号
// 国家标准《GB 11643-1999》
function rid18(id) {
if(! /\d{17}[\dxX]/.test(id)) {
return false;
}
var modcmpl = function(m, i, n) { return (i + n - m % i) % i; },
f = function(v, i) { return v * (Math.pow(2, i-1) % 11); },
s = 0;