Skip to content

Instantly share code, notes, and snippets.

View daifu's full-sized avatar

Daifu Richard Ye daifu

View GitHub Profile
$.fn.html5_placeholder = function() {
var input = $(this);
input.focus(function() {
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
@daifu
daifu / deploy.rb
Created March 31, 2012 16:51 — forked from ahawkins/deploy.rb
Deploy script for Heroku apps
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
@daifu
daifu / PusSub.js
Created July 3, 2012 05:39
Javascript Web Application: PusSub Object
var PubSub = {
subscribe: function(ev, callback) {
// Create _callbacks object, unless it already exists
var calls = this._callbacks || (this._callbacks = {});
// Create an array for the given event key, unless it exists, then
// append the callback to the array
(this._callbacks[ev] || (this._callbacks[ev] = [])).push(callback);
return this;
},
publish: function() {
@daifu
daifu / PusSub.js
Created July 3, 2012 06:02
Javascript Web Application: PusSub With jQuery by Ben Alman
/*!
* jQuery Tiny Pub/Sub - v0.3 - 11/4/2010
* http://benalman.com/ *
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/ */
(function($){
var o = $({});
$.subscribe = function() { o.bind.apply( o, arguments );};
$.unsubscribe = function() { o.unbind.apply( o, arguments );};
@daifu
daifu / tab_delegation.js
Created July 3, 2012 18:11
Javascript Web Application: Delegation example
jQuery.fn.tabs = function(control){
var element = $(this);
control = $(control);
element.delegate("li", "click", function(){
// Retrieve tab name
var tabName = $(this).attr("data-tab");
// Fire custom event on tab click
element.trigger("change.tabs", tabName);
});
// Bind to custom event
@daifu
daifu / autolink.js
Created July 7, 2012 08:10
Javascript Web Application: autolink using helper
@daifu
daifu / grid-toggle.js
Created July 7, 2012 18:11 — forked from adamstac/grid-toggle.js
Create, show, and hide grid toggle with jQuery
$(document).ready(function() {
// Create, show, and hide grid toggle
$('body').append('<div id="grid"></div>');
$('body').append('<a href="#" class="toggle-grid"><span class="show">Show Grid</span><span class="hide">Hide Grid</span></a>');
$('a.toggle-grid').toggle(function() {
$('#grid').slideDown('fast');
$('.toggle-grid .hide').show();
$('.toggle-grid .show').hide();
}, function() {
@daifu
daifu / app.rb
Created July 8, 2012 09:25 — forked from maccman/app.rb
Sinatra Async UI chat
#!/usr/bin/env ruby
# coding: utf-8
require 'sinatra'
set :server, 'thin'
set :sessions, true
streams = Hash.new {|k, v| k[v] = [] }
helpers do
def session_id
@daifu
daifu / juggernaut_channels.rb
Created July 8, 2012 09:26 — forked from maccman/juggernaut_channels.rb
Sinatra Server Side Event streaming with private channels.
# Usage: redis-cli publish message.achannel hello
require 'sinatra'
require 'redis'
conns = Hash.new {|h, k| h[k] = [] }
Thread.abort_on_exception = true
get '/' do
@daifu
daifu / hr.less
Created July 8, 2012 19:39 — forked from maccman/hr.less
HR CSS3 Tapering
/* See http://cl.ly/8KmQ for an example */
hr {
margin: 15px 0;
position: relative;
border: 1px solid transparent;
.box-shadow(0, 1px, 2px, rgba(0,0,0,0.3));
&:before, &:after {
content: "";