Skip to content

Instantly share code, notes, and snippets.

View zhuochun's full-sized avatar

Zhuochun zhuochun

View GitHub Profile
@zhuochun
zhuochun / Underscore.js
Created October 22, 2012 09:04
Extend Methods in JavaScript
/*
-> http://underscorejs.org/#extend
extend(destination, *sources)
Copy all of the properties in the source objects over to the destination object, and return the destination object.
It's in-order, so the last source will override properties of the same name in previous arguments.
*/
@zhuochun
zhuochun / js template.js
Created October 28, 2012 15:46
RequireJS + jQuery
/* ========================================
* <Project> - <Description>
*
* Author:
* Last Edit:
* ========================================
* <License>
* ======================================== */
define(function(require, exports) {
@zhuochun
zhuochun / jQuery Plugin.js
Created October 28, 2012 15:47
jQuery Plugin Boilerplate
/* ========================================
* <Project> - <Description>
*
* Author:
* Last Edit:
* ========================================
* <License>
* ======================================== */
// the semi-colon before function invocation is a safety net against concatenated
@zhuochun
zhuochun / fixnavbar.js
Created December 6, 2012 03:34
Scroll Fix on Top Navbar
// fix navbar on scroll
var $win = $(window)
, $nav = $('.navbar')
, navTop = $('.navbar').length && $('.navbar').offset().top - 10
, isFixed = 0
processScroll()
$win.on('scroll', processScroll)
@zhuochun
zhuochun / run_async.js
Created April 21, 2013 10:11
Run a large batch of async tasks separated
var complete = {}, completed = 0;
var i, thread = 23, total = 179, max = (total / thread | 0) + 1;
function startCount(idx, max) {
if (completed >= total) {
console.log("completed = " + completed);
console.log(complete);
return ;
} else if (idx === max || idx >= total) {
function loadCss(css) {
var link;
if ($.isArray(css)) {
$.each(css, function (idx, lk) {
loadCss(lk);
});
} else {
link = document.createElement("link");
link.type = "text/css";
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.timestamps
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
@zhuochun
zhuochun / Macbook Air 2013 Webcam.md
Last active December 23, 2015 05:49
Solve New Mountain Lion Update Webcams not accessible from applications

After the latest OS X system update, Macbook Air 2013 Webcam no longer working on Chrome/Skype.

Solution

  1. Download the attached file.

  2. Go to Finder>Go>Go to Folder

  3. Copy and paste this into the search bar: /Library/CoreMediaIO/Plug-Ins/DAL/

=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
// Zhuochun
// 2013-12-15
function eventFire(el, etype) {
if (el.fireEvent) {
(el.fireEvent('on' + etype));
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);