Skip to content

Instantly share code, notes, and snippets.

View daihuaye's full-sized avatar

Daihua Ye daihuaye

View GitHub Profile
@daihuaye
daihuaye / gitCommand.sh
Last active August 29, 2015 14:08
Some useful command
$ git checkout -b serverfix origin/serverfix
Branch serverfix set up to track remote branch serverfix from origin.
Switched to a new branch 'serverfix'
How to see git log of someone who commit during date range
For example: I want to see all commits from "daihuaye" on 2/25/2015
$ git log --after="2015-2-25 00:00" --before="2015-2-25 23:59" --author="daihuaye"
Set ruby gem to current ruby version (guidevine) fix issue of bundle install
$ rvm rvmrc to ruby-version
@daihuaye
daihuaye / tip.js
Created October 26, 2014 18:09
JavaScript tips
// https://github.com/twbs/bootstrap/blob/master/js/carousel.js line 149
$next[0].offsetWidth // force reflow
@daihuaye
daihuaye / carousel.js
Last active August 29, 2015 14:08 — forked from barryvdh/carousel.js
@daihuaye
daihuaye / window.location.origin.js
Created October 27, 2014 21:50
window.location.origin in ie 9
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
@daihuaye
daihuaye / dataset.js
Created October 29, 2014 17:26
dataset is not worked in ie 9, pitfall
var myElement = document.getElementById('myElement'), // contains attribute data-my-custom-value
myCustomValue;
if(myElement.dataset !== undefined) { // standard approach
myCustomValue = myElement.dataset.myCustomValue;
} else {
myCustomValue = myElement.getAttribute('data-my-custom-value'); // IE approach
myElement.setAttribute('data-my-custom-value', 'new value') // set new value on the data attribute
}
@daihuaye
daihuaye / generateUid.js
Created November 4, 2014 04:56
unique random id
var generateUid = function() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c === 'x' ? r : (r&0x7|0x8)).toString(16);
});
return uuid;
};
@daihuaye
daihuaye / formattedPhoneNumber.js
Last active August 29, 2015 14:09
formate phone number to format
formattedPhoneNumber: function formattedPhoneNumber(phone) {
var formats = '(...) ...-....',
formattedPhone = '',
phoneDigits;
if (!phone) {
return;
} else if (phone.substring(0, 1) === '+') {
phoneDigits = phone.substring(2);
} else {
phoneDigits = phone.replace(/[^0-9]/g, '');
@daihuaye
daihuaye / isMobile.js
Created November 12, 2014 04:17
detect a handheld device in jQuery
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}
$.browser.device = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
@daihuaye
daihuaye / A Highly Configurable And Mutable Plugin.js
Created December 6, 2014 16:47
A Highly Configurable And Mutable Plugin
javascript
$('.item-a').draggable({'defaultPosition':'top-left'});
$('.item-b').draggable({'defaultPosition':'bottom-right'});
$('.item-c').draggable({'defaultPosition':'bottom-left'});
-->
javascript
$('.items').draggable();
html
@daihuaye
daihuaye / jQuery UI Widget Factory Bridge.js
Created December 6, 2014 16:48
jQuery UI Widget Factory Bridge
/*!
* jQuery UI Widget factory "bridge" plugin boilerplate
* Author: @erichynds
* Further changes, additional comments: @addyosmani
* Licensed under the MIT license
*/
// a "widgetName" object constructor