Skip to content

Instantly share code, notes, and snippets.

@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
@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 */
@luetkemj
luetkemj / wp-query-ref.php
Last active April 25, 2024 09:37
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
@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 ) )
@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/
*/
@coolaj86
coolaj86 / how-to-publish-to-npm.md
Last active April 2, 2024 20:18
How to publish packages to NPM

Getting Started with NPM (as a developer)

As easy as 1, 2, 3!

Updated:

  • Aug, 08, 2022 update config docs for npm 8+
  • Jul 27, 2021 add private scopes
  • Jul 22, 2021 add dist tags
  • Jun 20, 2021 update for --access=public
  • Sep 07, 2020 update docs for npm version
@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 {
@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 );
@markjaquith
markjaquith / activate-deactivate-uninstall-example.php
Created March 6, 2011 17:27
Example code for doing activate/deactivate/uninstall hooks in a WordPress plugin
<?php
// Change /*CUSTOMIZE_THIS*/ to a unique name (two places). Go ahead, make it long.
// Like, your initials, and your full plugin name.
// e.g. MTJ_Some_Awesome_Plugin_Controller
/*CUSTOMIZE_THIS*/_Controller::init();
class /*CUSTOMIZE_THIS*/_Controller {
function init() {
@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