Skip to content

Instantly share code, notes, and snippets.

#times-tools, hr {
display: none;
}
@jcartledge
jcartledge / partial.php
Created July 22, 2013 23:31
Partial application and function composition in PHP.
<?php
/**
* Decorate a function so it can be partially applied.
*
* If the resulting function is called with fewer than the required
* number of arguments a new function is returned with the supplied
* arguments applied.
*
* See examples below.
diff --git a/repl/repl.py b/repl/repl.py
index dfdfaf0..a3a37cb 100644
--- a/repl/repl.py
+++ b/repl/repl.py
@@ -1,4 +1,5 @@
import re
+from os import path
from functools import reduce
from . import PY3K
@jcartledge
jcartledge / make_tsv
Created March 22, 2013 03:33
Parse timestamps, queries and facets out of Apache Solr logs.
#!/usr/bin/env bash
cat 20* | grep solr/select | perl -MURI::Escape -ne 's/(\d+\.\d+\.\d+\.\d+)[\s\-]+\[([^\]]+)\] "GET \/solr\/select.*(&fq=([^&]*)?).*(&q=([^&]*)?).* 200 /\2\t\6\t\4\t/ && print uri_unescape($_)' -
@jcartledge
jcartledge / Cucumber CSS selector limit test.md
Last active December 13, 2015 16:48
Cucumber step to check that no linked stylesheets have too many selectors.

Hopefully you never have to do this, but if e.g. you build a lot of stuff on top of a library like Bootstrap and then concatenate all your CSS for shipping you might find that you hit [IE<10's 4095-selectors-per-sheet limit][ielimit].

To guard against this we added the following to our [Cucumber][cucumber] tests which run in our CI build.

This works with [Poltergeist][poltergeist] which is a [Capybara][capybara] adapter that wraps [PhantomJS][phantomjs].

It's arguably an abuse of Cucumber because we're definitely not testing behaviour here, but it's handy to have non-functional stuff like CSS bloat tracked in a continuous build, especially when the consequences include dropping styles on the floor.

If you're building a Rails app, skip this and use something like [css_splitter][css_splitter] to circumvent the issue.

@jcartledge
jcartledge / count-selectors-bookmarklet.js
Last active December 12, 2015 03:59
count selectors
javascript:void(function(){
var _log = function() {
var args = $.makeArray(arguments).join(' ');
if(this.console) {
console.log(args);
} else {
alert(args);
}
};
var _count_selectors = function(sheet) {
@jcartledge
jcartledge / README.md
Created December 4, 2012 10:26
git fix alias to help resolving merge/rebase conflicts: opens all unmerged files in sublimetext

This one-liner will create a git fix alias in your ~/.gitconfig file.

When a git merge or rebase fails with conflicts, git fix will open all the unmerged files in sublimetext.

Change subl -nw to $EDITOR or whatever you prefer if you don't use sublimetext.

@jcartledge
jcartledge / download-ie.sh
Created November 8, 2012 04:08
Just the part of ievms that downloads the VPC images
#!/usr/bin/env bash
# Hacked out of https://github.com/xdissent/ievms/blob/master/ievms.sh
set -o nounset
set -o errtrace
set -o errexit
set -o pipefail
curl_opts=${CURL_OPTS:-""}
@jcartledge
jcartledge / bee.rb
Created August 22, 2012 10:05
Homebrew formula for bee
require 'formula'
class Bee < Formula
homepage 'https://github.com/jcartledge/bee/'
url 'https://github.com/jcartledge/bee/tarball/master'
sha1 '7095c5c9ecd2e4040f92e32edb8c8d3a89864d05'
version '0.1'
def install
bin.install("src/bee")
@jcartledge
jcartledge / quine.php
Created May 15, 2012 04:11
PHP Quine
<?php $a = '<?php $a = \'!\';
echo preg_replace(\'/!/\', addslashes($a), $a, 1);';
echo preg_replace('/!/', addslashes($a), $a, 1);