Skip to content

Instantly share code, notes, and snippets.

@bmhatfield
bmhatfield / .zshrc
Last active October 8, 2024 08:49
OSX Keychain Environment Variables
# If you use bash, this technique isn't really zsh specific. Adapt as needed.
source ~/keychain-environment-variables.sh
# AWS configuration example, after doing:
# $ set-keychain-environment-variable AWS_ACCESS_KEY_ID
# provide: "AKIAYOURACCESSKEY"
# $ set-keychain-environment-variable AWS_SECRET_ACCESS_KEY
# provide: "j1/yoursupersecret/password"
export AWS_ACCESS_KEY_ID=$(keychain-environment-variable AWS_ACCESS_KEY_ID);
export AWS_SECRET_ACCESS_KEY=$(keychain-environment-variable AWS_SECRET_ACCESS_KEY);
@paulirish
paulirish / what-forces-layout.md
Last active November 15, 2024 16:45
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@mintindeed
mintindeed / client.php
Created July 28, 2013 04:35
This is a very simple API authentication method. It doesn't do any kind of flood protection, for example. In general an OAuth implementation would be better.
<?php
$server_url = 'http://example.com/endpoint/?ts=' . time();
$shared_secret = 'random string of text'; // This is the same in server and client
$public_key = 'hello world'; // Each client has its own allowed key, this key is the same in the server and client
$headers = array(
'x-pmc-key: ' . $public_key,
'x-pmc-signature: ' . md5( $public_key . $shared_secret ),
);
@alexkingorg
alexkingorg / add-term-if-not-exists.php
Created September 14, 2012 18:35
Treat WordPress custom taxonomy as meta data
<?php
// check for a term and insert it if it doesn't exist
if (!get_term_by('slug', $term_slug, $taxonomy)) {
wp_insert_term(__($term_name, 'localization-key'), $taxonomy, array(
'slug' => $term_slug
));
}
@mjangda
mjangda / allow-ids.php
Last active January 21, 2022 02:27
Don't let kses strip out ids from section tags
<?php
function x_allow_ids_on_tags() {
global $allowedposttags;
$tags = array( 'section', 'article' );
$new_attributes = array( 'id' => array() );
foreach ( $tags as $tag ) {
if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) )
$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
@achimnol
achimnol / sqlite_backup.py
Created June 30, 2012 03:13
A simple and safe SQLite3 backup script written in Python using ctypes + sqlite3 online backup API
#! /usr/bin/env python
# Of course, the author does not guarantee safety.
# I did my best by using SQLite's online backup API.
from __future__ import print_function
import sys, ctypes
from ctypes.util import find_library
SQLITE_OK = 0
SQLITE_ERROR = 1
SQLITE_BUSY = 5
@alanhogan
alanhogan / compass-retina-sprites.scss
Created June 5, 2012 23:21 — forked from thulstrup/compass-retina-sprites.scss
Using Compass to generate normal and retina sprite maps
$sprites: sprite-map("sprites/*.png");
$sprites-retina: sprite-map("sprites-retina/*.png");
@mixin sprite-background($name) {
background-image: sprite-url($sprites);
background-position: sprite-position($sprites, $name);
background-repeat: no-repeat;
display: block;
height: image-height(sprite-file($sprites, $name));
width: image-width(sprite-file($sprites, $name));
@bradvin
bradvin / jQuery.loadScript
Created April 5, 2012 19:03
conditional load script helper function with jQuery
jQuery.loadScript = function (url, arg1, arg2) {
var cache = false, callback = null;
//arg1 and arg2 can be interchangable as either the callback function or the cache bool
if ($.isFunction(arg1)){
callback = arg1;
cache = arg2 || cache;
} else {
cache = arg1 || cache;
callback = arg2 || callback;
}
@thulstrup
thulstrup / compass-retina-sprites.scss
Created March 20, 2012 19:18
Using Compass to generate normal and retina sprite maps
$sprites: sprite-map("sprites/*.png");
$sprites-retina: sprite-map("sprites-retina/*.png");
@mixin sprite-background($name) {
background-image: sprite-url($sprites);
background-position: sprite-position($sprites, $name);
background-repeat: no-repeat;
display: block;
height: image-height(sprite-file($sprites, $name));
width: image-width(sprite-file($sprites, $name));
@hmert
hmert / jquery-profile.js
Created January 1, 2012 06:53
jQuery Profiling Plugin
/*
* http://ejohn.org/blog/deep-profiling-jquery-apps/
* use: call jQuery.displayProfile(); in firebug console
*/
(function(){var log=[];var handle=jQuery.event.handle,ready=jQuery.ready;var internal=false;var eventStack=[];var curEvent=log[0]={event:"inline",methods:[],duration:0};if(!jQuery.readyList)jQuery.readyList=[];jQuery.readyList.unshift(function(){if(curEvent&&curEvent.event=="inline"&&curEvent.methods.length==0){log.shift()}if(curEvent)eventStack.push(curEvent);var e=curEvent=log[log.length]={event:"ready",target:formatElem(document),methods:[]};var start=(new Date).getTime();jQuery(document).bind("ready",function(){e.duration=(new Date).getTime()-start;curEvent=eventStack.pop()})});jQuery.event.handle=function(event){var pos=log.length;if(curEvent)eventStack.push(curEvent);var e=curEvent=log[pos]={event:event.type,target:formatElem(event.target),methods:[]};var start=(new Date).getTime();var ret=handle.apply(this,arguments);e.duration=(new Date).getTime()-start;curEvent=eventStack.pop();if(e.me