Skip to content

Instantly share code, notes, and snippets.

View lishiyo's full-sized avatar

Connie Li lishiyo

  • New York City
View GitHub Profile
@lishiyo
lishiyo / git-aliases
Last active March 10, 2022 03:26
GIT Alias
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --decorate --oneline --graph --date=short --abbrev-commit
histdate = log --decorate --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short --abbrev-commit
type = cat-file -t
dump = cat-file -p
w = whatchanged
@lishiyo
lishiyo / gulpfile.js
Last active August 29, 2015 14:18
Gulpfile Boilerplate - Browserify, Mocha, Phantom
// Gulp Dependencies
var gulp = require('gulp');
var rename = require('gulp-rename');
// Build Dependencies
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
// Style Dependencies
var sass = require('gulp-sass');
@lishiyo
lishiyo / AF-multipleEvents
Created July 10, 2014 23:58
structure of jQuery multiple events in one event listener
//two events, same callback
$( "div" ).on( "mouseenter mouseleave", function() {
console.log( "mouse hovered over or left a div" );
});
//two events, each with own callback
$( "div" ).on({
mouseenter: function() {
console.log( "hovered over a div" );
},
mouseleave: function() {
@lishiyo
lishiyo / AF-definedFunctions
Created July 10, 2014 23:55
anonymous versus defined jQuery functions
//event listener with anonymous callback function
$('mySelector').on('myEvent', function(e) {
/**callback function(s) here **/
});
//event listener with a defined callback function
function someFunction(e){
/**callback function(s) here **/
};
$('mySelector').on('myEvent', someFunction );
@lishiyo
lishiyo / jQueryEventDelegation
Last active August 29, 2015 14:03
simple event delegation structure
//traditional way
$( "#list a" ).on( "click", function() {
console.log( $( this ).text('I was clicked!') );
});
//event delegation way
$( "#list" ).on( "click", "a", function() {
console.log( $( this ).text('I was clicked!') );
});
//call the accordion plugin
$('.accordion').accordion();
//trigger the custom event and set it
panel.trigger('panelOpener');
$(".panel").on("panelOpener", function() {
// Developer 1: do Ajax stuff
});
$(".panel").on("panelOpener", function() {
// Developer 2: do saving stuff
});
@lishiyo
lishiyo / Demo - .one()method
Last active August 29, 2015 14:03
Blog - jQuery events
//calls handler once and sets up subsequent action
$( "button" ).one( "click", firstClick );
function firstClick() {
$('p').text( "You just clicked this for the first time!" );
// Set up the new handler for subsequent clicks with $(this).click
// (omit if no further click responses are needed)
$( this ).click( function(){
$('p').text( "You\'ve clicked this before!" );
@lishiyo
lishiyo / Toggling Methods
Last active August 29, 2015 14:03
methods for toggling between states
//general toggling - use another variable
var x = 0;
$('#toggle-btn').click(function(e){
if( x == 1 ){
$(this).removeClass('clicked');
x = 0;
} else {
$(this).addClass('clicked');
x = 1;
}
@lishiyo
lishiyo / 0_reuse_code.js
Created July 9, 2014 00:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
// Tear down all click handlers on a selector
$( "p" ).off( "click" );
// Tear down a particular click handler by passing its name in the second parameter
var firstHandler = function() { console.log( "some action" ); };
var secondHandler = function() { console.log( "another action" ); };
// both click handlers attached to "p" by chaining
$( "p" ).on( "click", firstHandler ).on( "click", secondHandler );
// tear down only firstHandler - secondHandler still attached