Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tomalak on github.
  • I am tomalak (https://keybase.io/tomalak) on keybase.
  • I have a public key whose fingerprint is 131F C1F5 BEFD 5B22 7E26 24F1 134E 854E 117D 1A21

To claim this, I am signing this object:

@Tomalak
Tomalak / linq-multilevel-grouping.js
Created January 3, 2015 23:44
linq.js Dynamic Multilevel Grouping
/* Utility functions to create a nested, multilevel grouped, ordered
* structure out of a flat array of uniform objects.
*
* usage: result = applyStructure(items, structure);
*
* structure is an object of the form:
* {
* group: "propertyName1"
* order: ["propertyName1", "propertyName2 DESC", ...]
* next: {
@Tomalak
Tomalak / knockout-undoBuffer.js
Created August 29, 2014 16:36
A "multi-level undo" extender for Knockout observables.
ko.extenders.undoBuffer = function (target, maxUndo) {
var undoBuffer = ko.observableArray([]), undoing;
target.canUndo = ko.computed(function () {
return undoBuffer().length > 0;
});
target.undo = function () {
if (!target.canUndo()) return;
undoing = true;
target(undoBuffer.pop());
public class IndexOfWord {
public static void main(String[] args) {
String input = "There are longer strings than this not very long one.";
String search = "long";
// using a StringBuilder enables passing a string as
// a function argument without creating a copy of it
int index = indexOfWord(new StringBuilder(input), search);
if (index > -1) {
@Tomalak
Tomalak / isNodeList.js
Last active May 11, 2024 15:22
A function to test if a JavaScript object is a DOM NodeList. This is designed to work across all browser implementations. StackOverflow question reference http://stackoverflow.com/a/7238344/18771.
/* Released under the MIT License in 2014. http://opensource.org/licenses/mit-license */
function isNodeList(nodes) {
var stringRepr = Object.prototype.toString.call(nodes);
return typeof nodes === 'object' &&
/^\[object (HTMLCollection|NodeList|Object)\]$/.test(stringRepr) &&
nodes.hasOwnProperty('length') &&
(nodes.length === 0 || (typeof nodes[0] === "object" && nodes[0].nodeType > 0));
}
@Tomalak
Tomalak / jquery.custom-selectors.count.js
Created March 14, 2014 15:57
jQuery custom selector :count
/* jquery.custom-selectors.count.js
*
* custom selector for finding elements that have a certain child/descendant count
*
* Usage: $("td:count(div, 3)") - all <td> that have 3 <div> as direct children
* $("td:countAll(div, 3)") - all <td> that have 3 <div> as descendants
*/
jQuery.extend(jQuery.expr[':'], (
function () {
@Tomalak
Tomalak / knockout-datalist.js
Created November 12, 2013 14:34
A knockout.js custom binding for HTM5 <datalist> based input fields. Explanation over here. http://stackoverflow.com/a/19867498/18771
/*
* enables convenient creation and use of HTML5 datalist inputs
* - knockout.js 2.3.0+
* - http://stackoverflow.com/a/19867498/18771
* - http://jsfiddle.net/GJ4h4/3/
*/
ko.bindingHandlers.datalist = (function () {
function getVal(rawItem, prop) {
var item = ko.unwrap(rawItem);
return item && prop ? ko.unwrap(item[prop]) : item;
@Tomalak
Tomalak / nexus.py
Last active December 27, 2015 15:09
#!/usr/bin/env python
import urllib, re
from collections import OrderedDict
url = 'https://play.google.com/store/devices'
data = urllib.urlopen(url).read()
matches = re.findall(r'\bNexus \d+', data)
devices = OrderedDict.fromkeys(matches).keys()
@Tomalak
Tomalak / jquery-tablesorter-textextractor.js
Created July 6, 2012 17:11
A custom textExtraction function for jQuery tablesorter that allows better sorting for accented characters and dates in dd.mm.yyyy format. Primarily targeted at German text; might work well for other languages.
// Details: StackOverflow (http://stackoverflow.com/a/614397/18771)
// License: cc-by-sa (http://creativecommons.org/licenses/by-sa/3.0/)
// Extends: jQuery Tablesorter 2.0+ (http://tablesorter.com)
// -------------------------------------------------------------------
// file encoding must be UTF-8!
function getTextExtractor()
{
return (function() {
var patternLetters = /[öäüÖÄÜáàâéèêúùûóòôÁÀÂÉÈÊÚÙÛÓÒÔß]/g;
@Tomalak
Tomalak / gist:15824
Created October 9, 2008 17:31
VBScript drag&drop mass file renaming
set fso = CreateObject("Scripting.FilesystemObject")
set shell = CreateObject("Wscript.Shell")
set args = wscript.Arguments
set re = New RegExp
set TodoList = CreateObject("Scripting.Dictionary")
appName = "File Rename Tool"
myname = wscript.scriptfullname
mypath = left(myname, instrrev(myname, "\") -1)
regkey = "HKCU\Software\vbsReplaceTool\"