Skip to content

Instantly share code, notes, and snippets.

@jcartledge
jcartledge / set.class.php
Last active August 9, 2020 18:25
PHP immutable set
<?php
function set() {
return new Set(func_get_args());
}
class Set implements Countable, Iterator {
private $data = array();
function __construct($data) {
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 / ll.js
Created July 1, 2013 01:31
Simple JavaScript implementation of cons list with lazy evaluation of map, filter etc.
// Basic cons list.
// Elements are defined as functions so we can have lazy sequences.
function cons(x, xs) {
return {
head: function() { return x; },
tail: typeof xs === 'function' ? xs : function() { return xs; }
};
}
function isEmpty(xs) { return xs === undefined; }
@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 / README.md
Created December 1, 2012 13:01 — forked from agnoster/README.md
Agnoster zsh theme with subtler colours and git 'no unstaged changes' state.

Fork of agnoster.theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

See the original gist for more details.

@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 / bash.sh
Created September 30, 2012 13:17
My git prompt is better than any other one I've seen anywhere.
# prompt
function _git_prompt() {
local git_status="`git status -unormal 2>&1`"
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
if [[ "$git_status" =~ Changed\ but\ not\ updated ]] || [[ "$git_status" =~ Untracked\ files ]] || [[ "$git_status" =~ Changes\ not\ staged ]] || [[ "$git_status" =~ Unmerged\ paths ]]; then
local color="0;31" # red
elif [[ "$git_status" =~ Changes\ to\ be\ committed ]]; then
local color="0;32"
else
local color="1;32"