Skip to content

Instantly share code, notes, and snippets.

/* Inspired by Python's useful re.findall method */
function findall(regex, str) {
var matches = [], m;
regex.lastIndex = 0;
while (m = regex.exec(str, regex.lastIndex)) {
matches[matches.length] = m;
}
return matches;
}
@allex
allex / gist:3199078
Created July 29, 2012 14:03
removing c-styled comments using javascript
// vim: set ft=javascript
// removing c-styled comments using javascript
function removeComments(str) {
// Remove all C-style slash comments
str = str.replace(/(?:^|[^\\])\/\/.*$/gm, '');
// Remove all C-style star comments
str = str.replace(/\/\*[\s\S]*?\*\//gm, '');
return str;
}
@allex
allex / .gitconfig
Created August 1, 2012 15:26 — forked from karlwestin/.gitconfig
Make git diff ignore whitespace and don't try to open jpgs and shit
# this can be put in [repo]/.git/config for local settings
# or ~/.gitconfig for global settings
# create a difftool "nodiff" that just returns true
# this path is for Mac. On linux it's /bin/true i guess
[diff "nodiff"]
command = /usr/bin/true
# make git ignore white space differences, many different possibilites here
@allex
allex / LCG_random.js
Created September 16, 2012 13:59
LCG_random
// http://en.wikipedia.org/wiki/Linear_congruential_generator
var LCG = function(seed) {
return function () {
seed = (214013 * seed + 2531011) % 0x100000000;
return seed * (1.0 / 4294967296.0);
};
};
var random = LCG(10);
@allex
allex / gist:4014879
Created November 5, 2012 02:03 — forked from nateps/gist:1172490
Hide the address bar in a fullscreen iPhone or Android web app
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>Test fullscreen</title>
<style>
html, body {
margin: 0;
padding: 0;
@allex
allex / gist:4095938
Last active October 12, 2015 22:27
.htaccess重写让空间绑定多个域名到不同的目录支持多站点
# see also http://www.freehao123.com/htaccess-godaddy/
# root .htaccess
<IfModule mod_rewrite.c>
# 关闭目录列表
Options -Indexes
RewriteEngine on
# 预设页面
DirectoryIndex default.html index.html default.html index.htm default.php index.php
# 统一网址,去掉www。如果你想保留www,自己在第二行添加
var util = exports || {};
util.mergeDeep = function(A, B, depth) {
var forever = depth == null;
for (var p in B) {
if (B[p] != null && B[p].constructor == Object && (forever || depth > 0)) {
A[p] = util.mergeDeep(A.hasOwnProperty(p) ? A[p] : {}, B[p], forever ? null : depth - 1);
} else {
A[p] = B[p];
}
@allex
allex / note.md
Last active December 14, 2015 03:09

NOTE.md

GistID: 5018623
GistURL: <https://gist.github.com/allex/5018623>
Author: Allex Wang (http://iallex.com)

GIT

@allex
allex / conn.bat
Last active December 14, 2015 11:29
@echo off
REM =====================================
REM Auto mount host server user directory
REM By allex (allex.wxn@gmail.com)
REM =====================================
if exist Z:\ goto :eof
echo Connecting host server, please wait . . .
ping HOST -n 5 >nul
// Author: Allex Wang (allex.wxn@gmail.com)
// GistID: 5098339
// GistURL: <https://gist.github.com/allex/5098339>
/**
* Generate a thumbnail by scaling images with canvas
* @method getThumbnail
* @param {String} str The original image src.
*/
var getThumbnail = function(src, opts, callback) {