Skip to content

Instantly share code, notes, and snippets.

/**
* Place this code in your theme's functions.php file to make the HTML
* it produces is more BEM friendly.
* This works out the menu_class value from wp_nav_menu() and uses that to create
* the class values.
*/
// Add a class to wp_nav_menu <li> tags so you get <li class="{menu_class}_item">
add_filter('nav_menu_css_class' , 'my_nav_special_class' , 10 , 3);
function my_nav_special_class($classes, $item, $args){
@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.
find ~/Sites/testsite -type f -exec dos2unix {} +
@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' {} '+'
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;
}

Avoid jQuery When Possible

jQuery does good jobs when you're dealing with browser compatibility. But we're living in an age that fewer and fewer people use old-school browsers such as IE <= 7. With the growing of DOM APIs in modern browsers (including IE 8), most functions that jQuery provides are built-in natively.

When targeting only modern browsers, it is better to avoid using jQuery's backward-compatible features. Instead, use the native DOM API, which will make your web page run much faster than you might think (native C / C++ implementaion v.s. JavaScript).

If you're making a web page for iOS (e.g. UIWebView), you should use native DOM APIs because mobile Safari is not that old-school web browser; it supports lots of native DOM APIs.

If you're making a Chrome Extension, you should always use native APIs, not only because Chrome has almost the latest DOM APIs available, but this can also avoid performance issue and unnecessary memory occupation (each jQuery-driven extension needs a separate

*Device* *Portrait* *Landscape* *Device type* *Remarks*
Nexus 7 600 961 Tablet
iPad 2 768 768 Tablet iOS always reports the same, regardless of orientation.
Surface RT 1366 1024 Tablet
Galaxy Tab 2 1280 800 Tablet
Galaxy Nexus 360 598 Phone
iPhone 5 320 320 Phone iOS always reports the same, regardless of orientation.
Galaxy S3 mini 320 534 Phone Stock android browser reports 533, not 534 (Chrome).