Skip to content

Instantly share code, notes, and snippets.

View jgarber623's full-sized avatar
:atom:

Jason Garber jgarber623

:atom:
View GitHub Profile
@jgarber623
jgarber623 / activate-and-close-lastfm-app.scpt
Created June 18, 2010 03:36
A simple AppleScript to launch Last.fm.app and hide its window
-- A simple AppleScript to launch Last.fm.app and hide its window
tell application "Last.fm" to activate
tell application "System Events" to keystroke "w" using command down
tell application "Finder" to activate
@jgarber623
jgarber623 / template.html
Created July 11, 2010 03:07
A sample (X)HTML5 template for use at Viget Labs
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6 lte8 lte7 lte6" lang="en"><![endif]-->
<!--[if IE 7 ]><html class="ie ie7 lte8 lte7" lang="en"><![endif]-->
<!--[if IE 8 ]><html class="ie ie8 lte8" lang="en"><![endif]-->
<!--[if !IE]><!--><html lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8" />
<title></title>
@jgarber623
jgarber623 / template.html
Created July 19, 2010 03:38
A sample (X)HTML5 template for personal use
<!DOCTYPE html>
<html lang="en" id="example-com">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="profile" href="http://microformats.org/profile/hcard" />
<link rel="stylesheet" media="screen" href="http://yui.yahooapis.com/3.1.1/build/cssreset/reset-min.css" />
<link rel="stylesheet" media="screen" href="stylesheets/screen.css" />
@jgarber623
jgarber623 / application.js
Created July 19, 2010 03:40
A sample JavaScript structure for larger web applications
/*
* Based on Paul Irish's "Markup-based unobtrusive comprehensive DOM-ready execution"
* http://paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/
*/
SITE_NAMESPACE = {
common: {
init: function() {
}
@jgarber623
jgarber623 / gridhelper.js
Created July 20, 2010 02:36
Grid Helper bookmarklet for web development
javascript:(function() {
if ( !document.getElementById( "__grid" ) ) {
d = document.createElement( "div" );
d.setAttribute( "id", "__grid" );
d.setAttribute( "style", "background: url('http://" + window.location.hostname + "/images/grid.png') repeat-y 50% 0; height: " + document.height + "px; left: 0; position: absolute; top: 0; width: 100%; z-index: 16000000;" );
document.body.appendChild( d );
} else {
document.body.removeChild( document.getElementById( "__grid" ) );
}
@jgarber623
jgarber623 / gridhelper.user.js
Created July 20, 2010 02:40
Grid Helper Greasemonkey script for web development
// ==UserScript==
// @name Grid Helper
// @namespace http://sixtwothree.org
// @description Grid Helper adds a keyboard shortcut and grid image (located at ~/images/grid.png)
// @include *
// @author Grid Helper by Jason Garber (http://sixtwothree.org)
// ==/UserScript==
window.gridhelper = {
isCtrl: false,
@jgarber623
jgarber623 / _rating_form.html.erb
Created August 18, 2010 15:17
An example of using layouts with partials in Rails
<form action="/path/to/some/action" method="post">
<ul id="rating-list">
<li class="average" style="width: 50px;"><span class="alt">2.5</span></li>
<%- (1..5).each do |score| -%>
<li class="rate-<%= score %>"><button type="submit" name="score" value="<%= score %>"><%= score %></button></li>
<%- end -%>
</ul>
</form>
@jgarber623
jgarber623 / create-front-end-project.sh
Created January 14, 2011 22:25
A simple script that pulls my version of the HTML5 Boilerplate into a folder (passed to the script as an argument), removes Git-related files, and opens the new folder in TextMate.
#!/bin/bash
############################################################
# create-front-end-project.sh
# Builds a project directory based on the following pattern:
#
# /[target_directory]
# images/
# content/
# layout/
@jgarber623
jgarber623 / date_utils.js
Created December 1, 2011 19:44
A couple of JS date utilities I used on a recent project
var date_utils = {
shift: function( date_obj, delta_in_days ) {
return new Date( date_obj.getTime() + ( delta_in_days * 86400000 ) );
},
epochTime: function( date_obj ) {
return date_obj.getTime();
}
}
@jgarber623
jgarber623 / complicated_regex_example.js
Created December 1, 2011 19:48
An obtuse Regular Expression that'll replace indices in input @name and @id attributes in multi-model Rails forms
// RegExplanation: Match last occurrence of "_<string>_" and replace with "_<new_string>_"
some_string.replace( /^(.*)_.+_(.*?)$/, "$1_" + new_fields_index + "_$2" ),
// RegExplanation: Match last occurrence of "][<string>][" and replace with "][<new_string>]["
some_string.replace( /^(.*)\]\[.+\]\[(.*?)$/, "$1\]\[" + new_fields_index + "\]\[$2" )