Skip to content

Instantly share code, notes, and snippets.

@jlgrall
jlgrall / findval.js
Last active August 29, 2015 14:25
Find an object or a value recursively in a webpage
// https://gist.github.com/jlgrall/0b8871bb0d84dc119630
function findVal(base, matcher, skip, filter, debug) {
"use strict";
// Check the arguments:
var i = 2,
args = arguments;
skip = Array.isArray(args[i]) ? args[i++] : [];
filter = typeof args[i] === "function" ? args[i++] : function() { return true; };
debug = args[i] === true;
@jlgrall
jlgrall / i18n-jqueryui-button.js
Created August 14, 2012 20:31
i18next: Adds support for data-i18n and data-i18n-options to jQuery UI Buttons
// Adds support for data-i18n and data-i18n-options to jQuery UI Buttons:
if( $.fn.button ) { // Checks the presence of the button component of jQuery UI
// Keep a reference to the original _create function:
var button_create_orig = $.ui.button.prototype._create;
$.ui.button.prototype._create = function( ) {
button_create_orig.apply( this, arguments );
if( this.type === "button" ) { // Not needed for input, radio or checkbox
var data_i18n = this.buttonElement.attr( "data-i18n" ),
i18n_options = this.buttonElement.data( "i18n-options" );
// If found, apply the attribute and datas to the button label:
@jlgrall
jlgrall / action.php
Last active January 4, 2016 15:08
Add basic Meltdown support
<?php
/**
* DokuWiki Plugin markdownextra (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <andi@splitbrain.org>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
@jlgrall
jlgrall / i18n-jqueryui-dialogtitle.js
Last active January 28, 2016 14:29
i18next: Adds support for data-i18n and data-i18n-options to jQuery UI Dialog's title
// Adds support for data-i18n and data-i18n-options to jQuery UI Dialog's title:
if( $.fn.dialog ) { // Checks the presence of the dialog component of jQuery UI
var rTitleKey = /\[title\]([^;]*);?/,
// Keep a reference to the original _create function:
dialog_create_orig = $.ui.dialog.prototype._create;
$.ui.dialog.prototype._create = function( ) {
var data_i18n,
i18n_options;
if( !this.options.title ) { // Because as defined in Dialog, the options.title should override the title attribute
var old_data_i18n = this.element.attr( "data-i18n" );
@jlgrall
jlgrall / test_PHPZipMerge_INCONS.php
Created July 20, 2016 09:29
Test case for inconsistent PHPZipMerge merged zip
<?php
// Put this file in a subdirectory inside the PHPZipMerge repository, then execute it.
error_reporting(E_ALL);
ini_set('open_basedir', dirname(__DIR__)); // Security: restrict file access to parent directory.
require __DIR__.'/../vendor/autoload.php';
$srcName = 'src.zip';
$src = __DIR__.'/'.$srcName;
if(file_exists($src)) unlink($src);
@jlgrall
jlgrall / test.js
Last active December 12, 2018 15:22
domvm test case: unnecessarily redrawing child vm when parent vm is also redrawing
var el = domvm.defineElement,
vw = domvm.defineView;
// State:
var color = "purple",
numbers = [{nb: 0}, {nb: 1}, {nb: 2}, {nb: 3}, {nb: 4}, {nb: 5}];
// Views:
function ListView() {
return function(vm) {
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>domvm-MobX Demo</title>
<style>
.section { margin-left: 1em; }
input[type=text] { width: 10em; }
#limit { width: 3em; }