Skip to content

Instantly share code, notes, and snippets.

@markjaquith
markjaquith / cws-posts-per-page.php
Created June 30, 2011 20:21
WordPress plugin example code to correctly set a custom number of posts to display per page, for specific types of views
<?php
/*
Plugin Name: CWS Posts Per Page
Version: 0.1
Description: Sets a custom number of posts to display per page, for specific types of views
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
class CWS_Posts_Per_Page_Plugin {
@markjaquith
markjaquith / login-logo-custom-css.php
Created January 15, 2012 01:30
Login form CSS customization
<?php
/*
Plugin Name: Login Logo Custom CSS
Description: Custom CSS for the login screen
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@markjaquith
markjaquith / gist:1645537
Created January 20, 2012 05:44
CWS_Plugin — Exploratory WordPress plugin parent class
<?php
if ( !class_exists( 'CWS_Plugin_v2' ) ) :
class CWS_Plugin_v2 {
public function hook( $hook ) {
$priority = 10;
$method = $this->sanitize_method( $hook );
$args = func_get_args();
unset( $args[0] );
foreach ( (array) $args as $arg ) {
if ( is_int( $arg ) )
@scribu
scribu / latency.txt
Created May 31, 2012 09:07 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Disk seek (SSD) 100,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
@pezholio
pezholio / gist:364477
Created April 13, 2010 10:08
A helper function for UK Postcodes, adapted from the original function I wrote for the Ernest Marples service
<?php
function ernest_marples($postcode) {
$postcode = str_replace(" ", "", $postcode);
$url = "http://www.uk-postcodes.com/postcode/". urlencode($postcode) .".csv"; // Build the URL
$file = file_get_contents($url);
if (strpos($file, "html") === FALSE) { // Some error checking - if the file contains html, then we've been redirected to the homepage and something has gone wrong

Development Contract Killer

A fork of the popular open-source contract for web designers and developers by Stuff & Nonsense, reworded for developers


Between us [company name] and you [customer name]

@Raysharr
Raysharr / better_setInterval.js
Created October 18, 2012 20:50
Paul Irish's better setInterval
/* From Paul Irish */
/* instead of */
setInterval(function(){ doStuff(); },100);
/* use anonymous self-executing function */
(function thisismyfunctionuniquename(){
doStuff();
setTimeout(thisismyfunctionuniquename,100);
@scribu
scribu / debug_rewrite.php
Created April 28, 2011 22:15
Debug WP_Rewrite
<?php
function debug_rewrite() {
global $wp, $wp_rewrite;
if ( !current_user_can( 'manage_options' ) )
return;
echo '<pre>';
var_dump( $wp->matched_rule );
print_r( $wp_rewrite );
@scribu
scribu / package-setup.sh
Created December 24, 2013 01:05
Set up the package index for WP-CLI
#!/usr/bin/env bash
if [ -z "$INSTALL_DIR" ]; then
INSTALL_DIR=$HOME/.wp-cli
fi
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
if [ ! -x composer.phar ]; then
@emilbjorklund
emilbjorklund / breakpoints_via_css.html
Created April 24, 2012 16:03
Width detection via sneaky CSS rules
<!DOCTYPE html>
<!--[if IE 8]> <html lang="sv-SE" class="no-js ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="sv-SE" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<title>Breakpoint detection test</title>
<style type="text/css" media="screen">
@media screen and (min-width: 320px) {
#page:after {
content: 'smallest'; /* represent the current width-bracket */