Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
var jar = new CookieJar({path: '/', expires: 31536000}),
// change these to match your site
en = 'example.com/en',
fr = 'example.com/fr',
// don't change this line or below
matcher = new RegExp([en, '|', fr].join('').gsub('.','\\.'));
// did they already set a preference?
var preferred = jar.get('language');
if(!!preferred){
@walterdavis
walterdavis / ScriptyFader.fwaction
Last active December 18, 2015 20:39
BETA 2! Updated version of ScriptyFader, uses Freeway 6 techniques, should still work in Freeway 5. Works inline or absolutely positioned.
<action-encoding>UTF-8</action-encoding>
<library-action name="style_accessors">
<action-version version="1.2.5">
Style Accessors
Get and set styles on any element, regardless where they were initially defined.
MIT License
Copyright (c) 2013 Walter Lee Davis
</action-version>
@walterdavis
walterdavis / Anonymize.fwaction
Last active December 18, 2015 11:09
Convert an element's ID-based style to a class-based style.
<action-encoding>UTF-8</action-encoding>
<library-action name="classname_functions">
<action-version version="0.1">
Classname getter and setter functions, heavily influenced by Prototype.js.
Copyright 2013 Walter Davis Studio.
License: MIT License.
</action-version>
<action-javascript>
if(!'test'.strip) String.prototype.strip = function() {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
@walterdavis
walterdavis / Gretel.fwaction
Created June 11, 2013 14:19
Lost in the woods, dropping breadcrumbs as they go...
<action-encoding>UTF-8</action-encoding>
<page-action name="com.wdstudio.gretel" title="Gretel">
<action-version version="0.1">
Gretel
Copyright 2013 Walter Lee Davis
Add trailing comments to each block-level tag.
</action-version>
<action-javascript>
function fwAfterEndBody(){
<!--[if lte IE 6]>
<meta HTTP-EQUIV="REFRESH" content="0; url="www.example.com/whatever/">
<![endif]-->
@walterdavis
walterdavis / gist:5628071
Created May 22, 2013 14:43
Convert TSV to JSON
In TextWrangler, open the TSV file and strip off the first line (header row).
Add a final Return character at the end of the file if there isn't one already.
Open the Search and Replace dialog and make sure the "GREP" checkbox is ticked.
Enter the following in the Search field:
(.+?)\t(.+?)\t(.+)\r
Enter the following in the Replace field:
["\1", "\2", "\3"],
@walterdavis
walterdavis / .htaccess
Last active December 17, 2015 13:59
Rewrite multiple CSS links (and HEAD styles) to a single sheet.
# Uncomment (remove the hash from) ONLY ONE of the following lines (first one is already uncommented):
AddHandler application/x-httpd-php .html .htm
# AddHandler application/x-httpd-php5 .html .htm
# AddType application/x-httpd-php .html .htm
# AddHandler x-httpd-php .html .htm
# end of the one-line options (use the first one that doesn't cause an error on your server).
# Or, if you are stranded on GoDaddy, uncomment BOTH following lines:
# AddType application/x-httpd-php .htm .html
# AddHandler x-httpd-php .htm .html
@walterdavis
walterdavis / file_decorator.js
Last active December 17, 2015 10:28
So, in my usual rather perverse fashion, I am force-fitting Prototype into Bootstrap, since I have a gigantic mental block where jQuery should be. It actually works pretty well. Here are some widgets I have made over the course of building projects with these two frameworks.
document.observe('dom:loaded', function(){
var file_decorator = function(){
$$('input.file').each(function(elm){
var elm = elm.hide();
if(elm.decorated) return;
elm['decorated'] = true;
var group = new Element('div', {
'class': 'input-append'
});
var txt = new Element('input', {
<action-encoding>UTF-8</action-encoding>
<page-action name="com.wdstudio.page_id" title="PageID">
<action-version version="0.1">
PageID
Copyright 2013 Walter Lee Davis
Add an ID to the body tag.
</action-version>
<action-text name="bodyId" title="Body ID" />
<action-checkbox name="enable" title="Add the ID" default=yes />
table.sortable {
border-collapse: collapse;
table-layout: fixed;
}
.sortable th, .sortable td {
border-bottom: 1px solid #ccc;
padding: 3px 6px 3px 16px;
}