Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
@jeremyworboys
jeremyworboys / README.md
Created January 28, 2014 03:34
Domain Independent wp-config.php

Dynamic Wordpress Config

This makes Wordpress play super friendly with Git :)

Usage

  1. Copy and paste this snippet in wp-config.php
  2. Enter the hostname of your production server on line 24
  3. Setup your database credentials for production and development (you can add more environments by adding a new case using that server's hostname)
  4. Replace the keys and salts block with the contents of https://api.wordpress.org/secret-key/1.1/salt/
@jeremyworboys
jeremyworboys / Data only.html
Created October 27, 2013 21:55
Separation of concerns with MVVM EE Stash
{!-- model.html --}
{exp:channel:entries
channel="work"
url_title="{stash:url_title}"
require_entry="yes"
{global:disable}
}
{exp:stash:set_list name="images"}
{post_carousel_images}
<?php
trait DefaultsModel {
/**
* Default values to seed the model with
* @var Array
*/
protected $defaults = array();
@jeremyworboys
jeremyworboys / .lighttpd
Created August 14, 2013 11:30
Test Lighthttpd config for Retina Images
HTTP["cookie"] =~ "devicePixelRatio" {
url.rewrite-final += ( "^{url}\.(jpe?g|gif|png|bmp)" => "/retinaimages.php" )
}
@jeremyworboys
jeremyworboys / regex.coffee
Created January 8, 2013 08:00
Regex to match CSS Color Module Level 3 colours. (Purposefully not including `inherit`.)
///
aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgrey|darkgreen|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|grey|green|greenyellow|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgrey|lightgreen|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midni
@jeremyworboys
jeremyworboys / after.html
Created October 31, 2012 04:23
GA Event Tracking
<div>
<a href="https://www.drivingschoolservices.com.au/idi_portal/login.aspx" onClick="_gaq.push(['_trackEvent', 'Driving School Services', 'Book Now']);" title="Book driving lessons online" target="_blank">
<img style="width: 162px; height: 65px;" alt="Book driving lessons online now" src="/portals/17/Book%20now%20blue.png">
</a>
&nbsp;
<a href="https://www.drivingschoolservices.com.au/idi_portal/login.aspx?su=1" onClick="_gaq.push(['_trackEvent', 'Driving School Services', 'Sign Up Now']);" title="Become a customer and book online" target="_blank">
<img style="width: 160px; height: 65px;" alt="Sign up to use our booking system" src="/portals/17/sign%20up%20180%20x%2065.png" longdesc="Sign up to use our booking system">
</a>
</div>
@jeremyworboys
jeremyworboys / gist:3952526
Created October 25, 2012 13:25
View all in EE template
{exp:channel:entries channel="CHANNEL_NAME" {if last_segment != "all"}limit="9"{/if} paginate="bottom"}
CHANNEL DATA
{paginate}
{pagination_links}
<a href="{path='{segment_1}/{segment_2}/{segment_3}/all'}">View All</a>
{/paginate}
{/exp:channel:entries}
{exp:query sql="
SELECT md.entry_id, cd.field_id_56, md.col_id_48
FROM exp_matrix_data AS md
LEFT JOIN exp_playa_relationships AS pr
ON md.entry_id = pr.parent_entry_id
LEFT JOIN exp_channel_data AS cd
ON pr.child_entry_id = cd.entry_id
WHERE md.field_id = 123
AND md.row_order = 1
GROUP BY md.entry_id
@jeremyworboys
jeremyworboys / preferences.json
Last active October 9, 2015 02:18
My Sublime Text 3 Prefs
{
"auto_complete_commit_on_tab": true,
"auto_complete_with_fields": true,
"auto_find_in_selection": true,
"bold_folder_labels": true,
"close_windows_when_empty": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"default_encoding": "UTF-8",
"dictionary": "Packages/Language - English/en_GB.dic",
"draw_white_space": "selection",