Skip to content

Instantly share code, notes, and snippets.

Avatar

Ken Snyder kensnyder

View GitHub Profile
@kensnyder
kensnyder / themefile.css
Created May 8, 2013
Example of hiding the image in the body of a Right Intel post
View themefile.css
.ri-image-wrapper {
display: none !important;
}
@kensnyder
kensnyder / repeated-ids.js
Created Feb 6, 2013
Find all repeated ids in a document
View repeated-ids.js
var ids = {};
var repeats = [];
document.body.innerHTML.replace(/ id="(.+?)"/g, function($0, $1) {
if (ids[$1]) repeats.push($1);
ids[$1] = true;
});
console.log(repeats);
// output
["carouselitem-2887", "carouselitem-2850", "slider-2887", "slider-2850", "carouselitem-2887", "carouselitem-2850", "carouselitem-2843", "slider-2887", "slider-2850", "slider-2843", "carouselitem-2887", "carouselitem-2850", "carouselitem-2843", "slider-2887", "slider-2850", "slider-2843", "carouselitem-2918", "carouselitem-2924", "carouselitem-2923", "carouselitem-2922", "carouselitem-2919", "carouselitem-2917", "carouselitem-2916", "carouselitem-2913", "carouselitem-2912", "carouselitem-2911", "carouselitem-2909", "carouselitem-2898", "carouselitem-2897", "carouselitem-2896", "carouselitem-2895", "carouselitem-2892", "carouselitem-2887", "carouselitem-2882", "carouselitem-2881", "carouselitem-2874", "slider-2918", "slider-2924", "slider-2923", "slider-2922", "slider-2919", "slider-2917", "slider-2916", "slider-2913", "sli
@kensnyder
kensnyder / casper-qsa.js
Last active Dec 10, 2015
Quick and Dirty jQuery-like function for Casper
View casper-qsa.js
function qsa(sel, each) {
return [].map.call(document.querySelectorAll(sel) || [], each || function(el) {return el});
}
// usage:
qsa('a[href*="/reports/"], .legend', function(el) {
el.style.visibility = 'hidden';
});
@kensnyder
kensnyder / myplugin.js
Created Dec 11, 2012
AMD Compatibility - Does this work?
View myplugin.js
function defineMyPlugin($) {
/*...*/
}
if (typeof define == 'function') {
define('MyPlugin', ['jquery'], defineMyPlugin);
}
else {
defineMyPlugin(jQuery);
}
@kensnyder
kensnyder / ppr.php
Created Dec 6, 2012
Pretty print_r
View ppr.php
<?php
// DEFAULT OPTIONS
$GLOBALS['ppr_mode'] = 'screen'; // mode = screen | popup | email | log | off
$GLOBALS['ppr_char_limit'] = 200;//1024 * 500;
$GLOBALS['ppr_str_limit'] = 1024 * 4;
$GLOBALS['ppr_backtrace_str_limit'] = 100;
$GLOBALS['ppr_backtrace_array_limit'] = 6;
$GLOBALS['ppr_backtrace_arg_limit'] = 5;
$GLOBALS['ppr_mailto'] = @$_SERVER['SERVER_ADMIN'];
@kensnyder
kensnyder / curry.php
Created Jun 12, 2012
Curry a function in PHP 5.3
View curry.php
<?php
class CurriedFunction {
public function __construct($callback/*[, $arg1][, $arg2][, $argN]*/) {
$this->args = func_get_args();
$this->callback = array_shift($this->args);
}
public function __invoke(/*[, $arg1][, $arg2][, $argN]*/) {
@kensnyder
kensnyder / app--plugins--find--models--behaviors--better_find.php
Created May 25, 2012
CakePHP Behavior to add Find Plugins to your models
View app--plugins--find--models--behaviors--better_find.php
<?php
/**
* Add custom find types to your model (CakePHP 1.3)
*/
class BetterFindBehavior extends ModelBehavior {
/**
* Trick to register methods in this class as custom find types
*
@kensnyder
kensnyder / router.php
Created Apr 30, 2012
Create a rule for how a URL should be routed including the view name and the $_GET variables to set
View router.php
<?php
function getViewPath($routes, $requestUri) {
// extract the path part of our url (e.g. '/news/3/1')
// and trim slashes
$url = trim( parse_url($requestUri, PHP_URL_PATH), '/');
if ($url == '') {
return 'views/home.php';
}
// get the values sent in the url
@kensnyder
kensnyder / gist:821334
Created Feb 10, 2011
Hide spammy posts on google groups
View gist:821334
var blacklist = {
title: [
/\bsexy?\b/i,
/online order/i,
/buy \w+ online/i,
/hot videos/i,
/earn money/i,
/prescription/i
],
body: [
View install-nodejs-couchdb-on-ubuntu.sh
#! /bin/sh
# oops need to first install http://packages.debian.org/sid/i386/libmozjs2d/download
# then http://packages.debian.org/sid/i386/libmozjs-dev/download
# init
mkdir nodejs-couchdb
cd nodejs-couchdb
# nodejs