Skip to content

Instantly share code, notes, and snippets.

function convertToChinese(num) {
num=''+num;
var ret='', ret2='', zero='';
var nWord=['零','一','二','三','四','五','六','七','八','九','十'];
var unitWord=['','十','百','千'], unitWord2=['','萬','億','兆'];
var rWord=[[/^一十/, '十']];
var n=num.replace(/\D/g,'').split('');
for(var i=0;i<n.length;i++) {
if(Math.floor((n.length-i-1)/4)>=unitWord2.length) {
ret2+= nWord[n[i]];
@metaphox
metaphox / cycleImages.js
Created July 24, 2011 21:36
cycleImages
timers = [];
var cycleImgs = function(imgs){
for(var j=0;j<timers.length;j++){clearTimeout(timers[j]);}
var selector = '#bgimg';
var gonext = function(imgarray, idx){
//console.log(imgarray[idx]);
var nextImage = new Image();
nextImage.onload = function(){
$(selector).stop().animate({opacity : 0 },
250,
function entry(metadata)
local postname = '_posts/' .. metadata.ref .. '.lua'
local pubdate = os.date("*t", metadata.pubdate)
print('Processing ' .. postname)
local convertedname = '_posts/' .. pubdate.year .. '-'
.. pubdate.month .. '-'
.. pubdate.day .. '-'
.. metadata.ref .. '.html'
print('Converting file into ' .. convertedname)
local f = assert(io.open(convertedname, 'w'))
@metaphox
metaphox / verndomainname.rb
Created December 6, 2011 23:56
a basic sinatra file for deploying on cloud foundry
require 'sinatra'
get(/.+/) do
send_sinatra_file(request.path) {404}
end
not_found do
send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
end
##generator pipes
import re
import os
import fnmatch
import gzip, bz2
def gen_find(filepat, top):
for path, dirlist, filelist in os.walk(top):
for name in fnmatch.filter(filelist, filepat):
@metaphox
metaphox / tryme.bf
Created January 11, 2012 16:18
yes, repl.it haz unicode, luke.
++[>++++++++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]<-]>+++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]>>++++++++++[>++++++++++<-]>+++++.<<<++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]>++[>++++ ++++[>++++++++<-]<-]>>.>+++++++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]+++++++++[>+++++++++<-]>[>>-<<-]>>------[<<<<->>>>-]<<<<.
@metaphox
metaphox / gist:1644401
Created January 20, 2012 01:34
Fixing the postgresql initdb fatal shared memory error on Leopard
Fixing the postgresql initdb fatal shared memory error on Leopard
Published Tue 18 December 2007 11:09 (+1300)
Tagged
software (43 posts and 3 photos)
mac os x (6 posts)
When doing the post-install setup of postgresql default database using initdb, you may hit this error:
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=1, size=1646592, 03600).
@metaphox
metaphox / normalized.html
Created January 23, 2012 10:03 — forked from scottkellum/normalized.html
pixel normalization
<!doctype html>
<html>
<head>
<!-- Encoding -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></meta>
@metaphox
metaphox / gist:1755841
Created February 6, 2012 23:23
General principles for good URI design
General principles for good URI design:
Don't use query parameters to alter state
Don't use mixed-case paths if you can help it; lowercase is best
Don't use implementation-specific extensions in your URIs (.php, .py, .pl, etc.)
Don't fall into RPC with your URIs
Do limit your URI space as much as possible
Do keep path segments short
Do prefer either /resource or /resource/; create 301 redirects from the one you don't use
Do use query parameters for sub-selection of a resource; i.e. pagination, search queries
// Helper function, used below.
// Usage: ['img1.jpg','img2.jpg'].remove('img1.jpg');
Array.prototype.remove = function(element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) { this.splice(i,1); }
}
};
// Usage: $(['img1.jpg','img2.jpg']).preloadImages(function(){ ... });
// Callback function gets called after all images are preloaded