Skip to content

Instantly share code, notes, and snippets.

View alanhogan's full-sized avatar

Alan Hogan alanhogan

View GitHub Profile

Here are some of the "gotchas" I've encountered when I converted all the javascript code into coffeescript. (BTW, this is gathered while coding for YourMechanic.com, a very cool mobile auto repair service.)

Disclaimer: Coffeescript is a great productivity booster for me personally. Even with all the things outlined below, it is still way better than javascript. None of these should discourage you from jumping into it right away.

Major gotchas

(Things that generate wrong code silently)

@alanhogan
alanhogan / autoselect.coffee
Created August 26, 2014 00:39
CoffeeScript Require.js Module for jQuery-based element selection on click
$ = require 'jquery'
module.exports = do ->
init = ->
$(document).on 'click', '.js-autoselect', (e) ->
range = document.createRange()
selection = window.getSelection()
range.selectNodeContents this
$four: "4";
$seven: "7";
$pi: 3.14159;
$phi: 1.618;
$null: null;
@if $seven > $four { // may only compare numbers on line 2 at column 9
.fourIsBiggerThanSeven {
color: green;
}
<?php
/*
Plugin Name: WP Mantis Tables
Plugin URI: http://www.rtprime.net/wpplugins/wpmantistables
Description: A plugin to allow you to insert a table of open issues from a mantis bugtracker database into a page on your Wordpress blog.
Version: 0.1.0
Author: rtprime
Author URI: http://www.rtprime.net
Copyright 2009 Robert Torres (e-mail: rtprime@mac.com)
@alanhogan
alanhogan / gist:1095312
Created July 20, 2011 16:38
Rails + Lion
[09:34] == Xiticity [44e3e0e4@gateway/web/freenode/ip.68.227.224.228] has joined #RubyOnRails
[09:34] -ChanServ- [#rubyonrails] Register with nickserv in order to talk: /msg nickserv help
[09:35] <Xiticity> As an OS X user and Rails 3.1 user -- is the consensus that it's fine to update to Lion, or should I hold off?
[09:35] <hedzup> Xiticity -- I upgraded to lion a few weeks ago
[09:35] <Xiticity> I don't want a shit-ton of problems to deal with, if waiting a few weeks should clear em up
[09:35] == RahulT [~rahult_@122-49-175-31.ip.adam.com.au] has quit [Quit: Leaving...]
[09:36] <Xiticity> how did it go, @hedzup
[09:36] <hedzup> you'll have to reinstall Xcode to get the dev tools
[09:36] <hedzup> i couldn't even do simple commands like "make" let alone any of the rails commands
[09:36] <Cervajz> Xiticity: I have Lion for two weeks and I actove develop in rails without problem. But for 3.0.9
@alanhogan
alanhogan / Stack trace (Webbrick)
Created August 30, 2011 01:43
When I omit sass-rails ~> 3.1.0.rc (group :assets)
/Users/my_username/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc8/lib/rails/railtie/configuration.rb:78:in `method_missing': undefined method `sass' for #<Rails::Application::Configuration:0x000001033b6d58> (NoMethodError)
from /Users/my_username/.rvm/gems/ruby-1.9.2-p180/bundler/gems/compass-22e2458b7751/lib/compass/configuration/helpers.rb:82:in `block in configure_rails!'
from /Users/my_username/.rvm/gems/ruby-1.9.2-p180/bundler/gems/compass-22e2458b7751/lib/compass/configuration/helpers.rb:81:in `each'
from /Users/my_username/.rvm/gems/ruby-1.9.2-p180/bundler/gems/compass-22e2458b7751/lib/compass/configuration/helpers.rb:81:in `configure_rails!'
from /Users/my_username/.rvm/gems/ruby-1.9.2-p180/bundler/gems/compass-22e2458b7751/lib/compass/app_integration/rails/actionpack31/railtie.rb:86:in `block in <class:Railtie>'
from /Users/my_username/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc8/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/my_username/.rvm/g
@alanhogan
alanhogan / gist:1184841
Created August 31, 2011 21:56
Meta Charset Heuristic
/ \b
charset=
['"]? # optional quotes
( # Capture
(?: # Non-capturing group, essentially a custom char class
\w # word characters
|
- # or hyphen
)+
)
@alanhogan
alanhogan / humane-ajh.coffee
Created February 4, 2012 05:06
Modified humane.js
# humane.js
# Humanized Messages for Notifications
# @author Marc Harter (@wavded)
# @example
# humane('hello world');
# See more usage examples at: http://wavded.github.com/humane-js/
#
# Modified by Alan Hogan (@alanhogan)
# (Diverged 2012-01-27.)
@alanhogan
alanhogan / gist:3222391
Created August 1, 2012 01:25
Bookmarklet/script: Allow sub-pixel text rendering (because Posterous sucks)
javascript:void((function(){var d=document;var ocss='html body, html body *{-webkit-font-smoothing: auto !important;}';var l='style'; var L=d.createElement(l);L.innerHTML=ocss; document.getElementsByTagName('head')[0].appendChild(L);})())
@alanhogan
alanhogan / gist:3222589
Created August 1, 2012 01:45
PREVENT sub-pixel font rendering (good for screenshots)
javascript:void((function(){var d=document;var ocss='html body, html body *{-webkit-font-smoothing: antialiased !important;}';var L=d.createElement('style');L.innerHTML=ocss; document.getElementsByTagName('head')[0].appendChild(L);})())