Skip to content

Instantly share code, notes, and snippets.

View melchoy's full-sized avatar
👩‍💻

Melissa Choy melchoy

👩‍💻
View GitHub Profile
@melchoy
melchoy / clickables.js
Created November 18, 2009 11:08
Clickable blocks for link target
/************************************
* Clickables (big block targets)
***********************************/
var Clickables = Class.create({
initialize: function(options) {
selector = $$(options.selector) || $$(".clickables");
this.clickable = options.clickable || "li";
this.hoverclass = options.hoverclass || "over";
@melchoy
melchoy / detectflash.js
Created January 2, 2010 03:15
Flash Player Detection
/**********************************************
* Flash Player Detection (taken from sifr )
**********************************************/
var hasFlash = function(){
var nRequiredVersion = 9;
if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
@melchoy
melchoy / gist:267366
Created January 2, 2010 03:20
handleExternalLinks
handleExternalLinks: function() {
var hostName = window.location.hostname;
var links = document.getElementsByTagName("a");
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf(hostName) == -1) {
var curTitle = (links[i].getAttribute("title")) ? links[i].getAttribute("title") + " - ": "";
links[i].setAttribute("target", "_blank");
links[i].setAttribute("title", curTitle + "opens in new window");
}
}
@melchoy
melchoy / mobile_site.rb
Created February 16, 2012 07:26
Mobile Subdomains in Rails
module MobileSite
def self.included(base)
base.class_eval do
# Uncomment for JQM Integration
#rescue_from ActionView::MissingTemplate, :with => :view_unavailable
before_filter :set_mobile_preferences
before_filter :redirect_to_mobile_if_applicable
before_filter :set_mobile_view_path
@melchoy
melchoy / bootstrap.rb
Created March 30, 2012 07:31 — forked from jamiepenney/bootstrap.rb
Form builder for Twitter Bootstrap v2 form elements
# This file goes in config/initializers
require 'bootstrap_form_builder'
# Make this the default Form Builder. You can delete this if you don't want form_for to use
# the bootstrap form builder by default
ActionView::Base.default_form_builder = BootstrapFormBuilder::FormBuilder
# Add in our FormHelper methods, so you can use bootstrap_form_for.
ActionView::Base.send :include, BootstrapFormBuilder::FormHelper
@melchoy
melchoy / application.rb
Created March 30, 2012 07:41 — forked from t2/application.rb
Formatting Rails form elements for Twitter Bootstrap error validation
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
# add nokogiri gem to Gemfile
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
elements.each do |e|
if e.node_name.eql? 'label'
html = %(<div class="clearfix error">#{e}</div>).html_safe
elsif e.node_name.eql? 'input'
if instance.error_message.kind_of?(Array)
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
@melchoy
melchoy / powssl
Created May 7, 2012 00:27 — forked from paulnicholson/powssl
ssl with pow using stud

Instructions

  • Install stud $ brew install https://raw.github.com/paulnicholson/homebrew/master/Library/Formula/stud.rb
  • Download and install the powssl script $ curl https://raw.github.com/gist/2050941/3ea59efe8c7e9013c265313045a9fdda5c653963/powssl > ~/bin/powssl $ chmod +x ~/bin/powssl
  • Run powssl to create development certificate and configure stud.
  • $ powssl
@melchoy
melchoy / config.ru
Created May 22, 2012 11:04 — forked from brookr/config.ru
Rackup file I use for running WordPress on Pow
# config.ru for Pow + Wordpress, based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/
# added hackery to work around wordpress issues - Patrick Anderson ([email protected])
# clearly this could be cleaner, but it does work
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
# patch Php from rack-legacy to substitute the original request so
# WP's redirect_canonical doesn't do an infinite redirect of /
@melchoy
melchoy / README.markdown
Created June 1, 2012 05:33 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string
@melchoy
melchoy / ruby-class.js
Created June 1, 2012 13:26 — forked from michealbenedict/ruby-class.js
Ruby-style classes in ECMAScript 5
var Class = Object.create(null, {
"new": {
"value": function () {
var result = Object.create(this, {
"class": {
"value": this
}
});
result.initialize.apply(result, arguments);
return result;