Skip to content

Instantly share code, notes, and snippets.

View salami162's full-sized avatar

Limin Shen salami162

  • Lyft
  • San Francisco, CA
View GitHub Profile
@salami162
salami162 / gist:5332074
Last active July 5, 2016 14:22
How do you implement an extend function that takes an object and extends itwith new properties and makes it work on n levels of recursion? Basically, duplicating a jQuery extend.
/**
* Implement Foo Object.
* - Take a JSON object as an input parameter
* - Create a copy this JSON object as itself.
* - Chainable
*/
var foo = new Foo({
version : '1.0'
});
@salami162
salami162 / gist:5332214
Last active December 15, 2015 22:19
How to use $.ajax request. How to use $.Deferred()
/**
* submit function:
* - take userToken as a input parameter
* - request form schema with the userToken if it exists.
* - display form schema on the page.
*/
<div id="message"></div>
function submit (data) {
@salami162
salami162 / gist:5332700
Last active December 15, 2015 22:19
How to implement batch request? How to user $.Deferred() to handle batch request limit? How to handle batch request collision?
/**
* If you have a widget on a page.
*/
var FacebookWidget = function (userName) {
this.username = userName;
this.user = new User(userName);
this.friends = new FriendList(userName);
this.activities = new ActivityList(userName);
}
@salami162
salami162 / forceGraph.js
Created May 30, 2013 04:00
An object created based on D3.js force graph. Thought worth to share it. e.g. var graph = new forceGraph ('#chart', 1000, 800, backboneView); graph.draw({ nodes : [...], links : [...] });
define([
'underscore',
'd3.v3'
], function (_, d3) {
function forceGraph (selector, width, height, view) {
this.margin = [20, 20, 20, 20];
this.r = 10;
this.width = (width - this.margin[1] - this.margin[3]) || 800;
this.height = (height - this.margin[0] - this.margin[2]) || 600;
@salami162
salami162 / .bash_profile
Last active December 21, 2015 01:09
Configuration Settings
# git bash-completion
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
# block='\e[0;30m' # Black - Regular
# txtred='\e[0;31m' # Red
# txtgrn='\e[0;32m' # Green
# txtylw='\e[0;33m' # Yellow
# txtblu='\e[0;34m' # Blue
@salami162
salami162 / Get Started.md
Created August 13, 2013 21:27
Setup Dev Environment

Getting Started

This document explains how to get Node.js applications running on your machine.

Setting up a Mac

XCode

Download XCode from the Apple App Store. Once you've installed XCode, you'll also need to install the Command Line Tools for XCode. Go to XCode > Preferences, click on the Downloads tab, and install the tools from there.

Homebrew

@salami162
salami162 / debugiPhone.md
Created August 13, 2013 21:37
Debug Safari on iPhone

Here is an overview of how to use the Web Inspector Tools to debug the Safari browser on the iPhone. You can also debug on an actual iPhone but the simulator that comes with Xcode should be sufficient in most situations. Below you will find the instructions on how to debug using the iOS Simulator.

Prerequisites

  1. Mac OSX Lion (10.7.4) or higher
  2. Safari 6
  3. Xcode 4.5 or higher iOS6 SDK (available in the app store)

Steps

  1. Open up the Xcode App. Right click on the Xcode icon and navigate to the iOS Simulator app. Open the Safari app and navigate to the URL you need to debug.
    xcode iOS Simulator
@salami162
salami162 / repo_cleanup.sh
Created October 22, 2013 22:54
Clean github repo
#!/bin/bash
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
echo "$remote_branches"
for remote in $remote_branches
do
read -p "Delete branch $remote? (y/n): " -n 1 choice
echo