Skip to content

Instantly share code, notes, and snippets.

@redroot
redroot / labelfinder
Created September 16, 2011 09:50
Picking up label text on input click with jQuery
/*
Take a look at the console http://jsbin.com/onipeq/
*/
$("input").live("click",function(){
label = findLabel($(this));
console.log(label);
});
function findLabel(/* jQuery Element */ el){
@redroot
redroot / gist:1234393
Created September 22, 2011 09:13
Different attempts to find order of visible elements in a form with jQuery
var f = $("#form");
// attempt 1: average abbout 2.621 seconds
(function(){
i = 0;
j = 0;
start = new Date().getTime();
for(j = 0; j < 1000; j++){
f.find(':visible').find("input,select,textarea,button").not("[type=hidden],[type=submit]").map(function() { return { order: i++, name: $(this).attr("name") }; } );
}
@redroot
redroot / gist:2644317
Created May 9, 2012 12:58
Adtech Aliases
// run in webkit console
$("script").filter(function(){
return ($(this).attr("src") || "").indexOf("alias") !== -1;
}).map(function(){
return $(this).attr("src").split("alias=")[1].split(";")[0];
});
// jquery safe mode
<!DOCTYPE html>
<!--[if lt IE 7]> <html dir="ltr" lang="en-US" class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html dir="ltr" lang="en-US" class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html dir="ltr" lang="en-US" class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html dir="ltr" lang="en-US"> <!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport' />
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta content='yes' name='apple-mobile-web-app-capable' />
@redroot
redroot / gist:3838739
Created October 5, 2012 08:23
Wordpress: Find posts with a specific meta key
# swap out 'videoid' for whichever meta keys you want
SELECT A.ID, B.post_id, A.post_title, A.post_date FROM
(SELECT ID,
post_date, post_title
FROM wp_posts
WHERE post_status = "publish"
) as A
@redroot
redroot / gist:4252085
Created December 10, 2012 17:45
Adtech globals
props = Object.getOwnPropertyNames(window); for(prop in props) { if(props[prop].toLowerCase().toString().indexOf("adtech") != - 1){ console.log(props[prop]); } }
@redroot
redroot / gist:4473719
Created January 7, 2013 09:39
Weighted Mean - Ruby
# array of arrays
a = [[10, 1000], [9, 923], [8, 1230], [7, 10]] # [data,frequency]
mean = a.reduce(0) { |m,r| m += r[0] * r[1] } / a.reduce(0) { |m,r| m += r[1] }.to_f
@redroot
redroot / gist:4997131
Created February 20, 2013 17:06
Example Wordpress Customiser Category Dropdown Control
<?php
class WP_Customize_Category_Control extends WP_Customize_Control {
public $type = 'dropdown-category';
public function render_content() {
$dropdown = wp_dropdown_categories(array(
"selected" => $this->value(),
"name" => $this->settings["default"]->id,
"echo" => 0
));
# name: rick
# description: The best bolt
# keyword: rick
result(title:"rick", description:"No strangers to love", action: actions.open("http://www.youtube.com/watch?gl=GB&hl=en-GB&v=oHg5SJYRHA0"))
@redroot
redroot / gist:8932682
Last active August 29, 2015 13:56
NewRelic: Delete Servers with No Data
window.confirm = function() {
console.log.apply(console, arguments); return true;
};
$(".host_status[data-traffic_light_level=3], .host_status[data-traffic_light_level=4]").each(function(i,el){
var p = $(this).parent();
var del = $(p).find(".delete_link.to_spinner");
var no_data = $(p).find(".no_data").length > 0;
if(no_data && del.length > 0){
setTimeout(function() {
console.log($(p).find(".app_name").text());