Skip to content

Instantly share code, notes, and snippets.

@abozhilov
abozhilov / gist:2997730
Created June 26, 2012 18:23
Wildcard to RegExp
/**
* Convert wildcard pattern to RegExp
* Pattern:
* * - Zero or more characters
* ? - Exactly one character
*
* @param {String} pattern Wildcard pattern
* @returns {RegExp} regular expression for wildcard matching
*/
function wc2reg(pattern) {
@dherman
dherman / map-dict.js
Created June 9, 2012 02:42
Map vs object for dictionary
// A Dict class that works in ES6 using Map. Basically it's identical to Map, but
// only expected to be used on string keys.
function Dict() {
this.elts = new Map();
}
// (string) -> any
Dict.prototype.get = function get(key) {
return this.elts.get(key);
anonymous
anonymous / gist:2507667
Created April 27, 2012 09:07
RegExp creation
var REGEX = {
NUMBER : /^-?[0-9]*\.?[0-9]+$/,
KEYWORD : /^(?:top\s+|bottom\s+)?(?:right|left)|(?:right\s+|left\s+)?(?:top|bottom)$/
};
var direction = RegExp([
'^(?:',
REGEX.NUMBER.source.slice(1, -1),
'|',
'(?:', REGEX.KEYWORD.source.slice(1, -1), ')deg',
@sillage
sillage / common.js
Created December 16, 2011 22:49
common.js
// *********************************************************************
// Add a new button in the toolbar which replaces `s' caracters by a
// `ſ' (long s, old style), but NOT at the end of a word.
// *********************************************************************
$(function() {
$.getScript('https://fr.wikisource.org/w/index.php?title=Utilisateur:FitzSai/xregexp.js&action=raw', // load XRegExp
function() {
$.getScript('https://fr.wikisource.org/w/index.php?title=Utilisateur:FitzSai/unicode-base.js&action=raw', // load Letter category only
function() {
!function() {
var doc = document,
htm = doc.documentElement,
lct = null, // last click target
nearest = function(elm, tag) {
while (elm && elm.nodeName != tag) {
elm = elm.parentNode;
}
return elm;
};