Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Hungry Kid!</title>
<style type="text/css">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Drag and Drop</title>
<style type="text/css">
body {
margin:15px;
padding:0;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Hungry Kid!</title>
<style type="text/css">
@pgchamberlin
pgchamberlin / MutationObserverLogger.js
Created December 5, 2012 17:47
Snippet that logs DOM mutations using the MutationObserver API
<script type="text/javascript">
// See MDN: https://developer.mozilla.org/en-US/docs/DOM/MutationObserver?redirectlocale=en-US&redirectslug=DOM%2FDOM_Mutation_Observers
(function(){
// select the target node
var target = document.querySelector('body');
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var i=0;
// create an observer instance
var observer = new MutationObserver(function(mutations) {
@pgchamberlin
pgchamberlin / nbspBetweenLastWords.php
Last active December 14, 2015 05:59
In response to @smashingmag's tweet: https://twitter.com/smashingmag/status/306416073408929792 an alternative method.
<?php
function nbspBetweenLastWords( $text, $minWords = 3 ) {
if (substr_count($text, ' ') >= $minWords - 1) {
return substr_replace($text, '&nbsp;', strrpos($text, ' '), 1);
}
return $text;
}
@pgchamberlin
pgchamberlin / DominantColours.php
Last active December 12, 2020 21:11
PHP class to extract dominant colours from an image using K-Means clustering. This features an extremely rough-and-ready (read: inefficient) implementation of K-Means which I wrote to run on PHP < 5.3. If you can use an up-to-date build of PHP then you can take advantage of some proper implementations that proper maths-type people have written f…
<?php
/**
* Dominant colours by k means derived from code by Charles Leifer at:
* http://charlesleifer.com/blog/using-python-and-k-means-to-find-the-dominant-colors-in-images/
*
* MagickWand docs: http://www.magickwand.org/
*
* Color transformation algorithms from EasyRGB: http://easyrgb.com/
*
@pgchamberlin
pgchamberlin / gist:9619843
Last active August 29, 2015 13:57
Functional vs procedural loops in PHP
class someclass
{
private $items;
function filterItemsUsingForeach()
{
$criterion = 'somevalue';
$items = array();
foreach ($this->items as $item) {
if (method_exists($item, 'someMethod') && $item->someMethod() == $criterion) {
@pgchamberlin
pgchamberlin / gist:10633516
Created April 14, 2014 09:53
Jasmine data provider helper
//Data provider functionality in jasmine
//see http://blog.jphpsf.com/2012/08/30/drying-up-your-javascript-jasmine-tests
function using(name, values, func){
for (var i = 0, count = values.length; i < count; i++) {
if (Object.prototype.toString.call(values[i]) !== '[object Array]') {
values[i] = [values[i]];
}
func.apply(this, values[i]);
jasmine.currentEnv_.currentSpec.description += ' (with "' + name + '" using ' + values[i].join(', ') + ')';
}
@pgchamberlin
pgchamberlin / vim_browse
Last active August 29, 2015 14:02
Vim command to open file in Chrome
# Open the current file in Chrome in OSX from Vim
# Add this to ~/.vimrc
# Usage: `:Browse`
command Browse execute "!/usr/bin/open -a \"/Applications/Google Chrome.app\"" expand('%:p')
@pgchamberlin
pgchamberlin / ilabcode2_1.py
Created June 30, 2014 14:18
Dev on AWS: Lab 2.1 code
import boto
from boto.s3.key import Key
class Ilabcode:
def create_bucket(self, s3_client, bucket_name, region):
pass
def put_object(self, s3_client, bucket_name, source_file_name, object_key):
pass