Skip to content

Instantly share code, notes, and snippets.

@yumyo
yumyo / toggleClass.js
Created November 13, 2012 15:43
JavaScript toggleClass Function
/**
* @author Joshua Heller
*/
function hasClass(ele, cls) {
return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function addClass(ele, cls) {
if (!this.hasClass(ele, cls))
ele.className += " " + cls;
@yumyo
yumyo / toggleclass.js
Created November 13, 2012 15:43
JavaScript toggleClass() function
/**
* toggleClass()
* Expects parameters
* elem = DOM element (object, instanceof HTMLElement)
* cl = Class name (string)
*/
var toggleClass = function(elem, cl) {
if (elem.className.indexOf(cl) != -1) {
elem.className = elem.className.replace(cl, '');
} else {
@yumyo
yumyo / remove-empty-p.php
Created November 16, 2012 17:10 — forked from ninnypants/remove-empty-p.php
Remove empty p tags from WordPress posts
add_filter('the_content', 'remove_empty_p', 20, 1);
function remove_empty_p($content){
$content = force_balance_tags($content);
return preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content);
}
@yumyo
yumyo / unix
Created November 29, 2012 18:24
Unix Directory search
To find the largest 10 files (linux/bash):
find . -type f -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
To find the largest 10 directories:
find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
Alternatively or a quick view:
@yumyo
yumyo / terminal network
Last active December 11, 2015 02:19
Ports operations on Mac OS X
List open ports on Mac OS X
sudo lsof -i -P | grep -i "listen"
--- Suspende node servers ---
ctrl-z suspends it, which means it can still be running.
ctrl-c will actually kill it.
@yumyo
yumyo / CRLF to LF
Created January 28, 2013 10:23
This will recursively convert CRLF to LF in non-binary files under the current directory —source: http://bit.ly/wJxtlK
find . -type f -exec grep -qIP '\r\n' {} ';' -exec perl -pi -e 's/\r\n/\n/g' {} '+'
find ~/Sites/testsite -type f -exec dos2unix {} +
wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains thewebsite.com --no-parent www.thewebsite.com
wget --recursive --no-clobber --page-requisites --html-extension --convert-links www.thewebsite.com
<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/
if (isset($_GET['instrument']) && $_GET['instrument']=='hooks') {
// Avoid `console` errors in browsers that lack a console.
if (!(window.console && console.log)) {
(function() {
var noop = function() {};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'markTimeline', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
var length = methods.length;
var console = window.console = {};
while (length--) {
console[methods[length]] = noop;
}