Skip to content

Instantly share code, notes, and snippets.

@phamd1989
phamd1989 / analytics.json
Created February 2, 2016 22:00
sample of analytics event
{"event":"DISCOVER_QUESTION_CLICKED","category":"NEW_EVENT","label":"TOP","value":"null","meta":{"device_id":"1369eb5fba4241e2","version":9999,"platform":"Android","user_id":"39486045"},"data":{"question_text":"What is the best movie you have ever seen?","question_id":null,"bucket":"LIKE","FEED_TYPE":"TOP","current_fragment":"DiscoverFragment","current_activity":"MainActivity"},"timestamp":1454450393022}
@phamd1989
phamd1989 / gist:818faaff3e1a47966de6
Created April 20, 2015 18:49
Interesting solution to the problem of finding the Longest Valid Parentheses substring
public class Solution {
public int longestValidParentheses(String s) {
int maxLen = 0;
// the index that right before the beginning of the current longest substring
int left = -1;
Stack<Integer> stack = new Stack<Integer>();
for (int i=0; i<s.length(); i++) {
if (s.charAt(i) == '(') {
stack.push(i);
@phamd1989
phamd1989 / deals
Last active August 29, 2015 14:09
Example
[
{
"company_deals": [
"\/steak-n-shake\/"
],
"title": [
"Buy 1, Get 1 Free Holiday Specialty Shakes "
],
"type": "In-store Coupon",
"image_url": [
@phamd1989
phamd1989 / CardsGame.py
Created February 14, 2014 20:54
Homework for SigFig
import random
class Card(object):
suits = {'C':'Club', 'D':'Diamond', 'H':'Heart', 'S':'Spade'}
ranks = {1:'Ace', 11:'Jack', 12:'Queen', 13:'King'}
def __init__(self, rank, suit):
# go from 1 to 13
self.rank = rank
@phamd1989
phamd1989 / Shorter_Detour.py
Created December 30, 2013 14:44
Solution to Lyft Programming Challenge
# This is to solve the Lyft Programming Challenge
import math
def distance_between(p1, p2):
"""This calculates the linear distance between two points
on a 2D coordinates system.
Args:
p1: the start point (a tuple of x,y coordinates)
p2: the end point (a tuple of x,y coordinates)
@phamd1989
phamd1989 / note for Backbone
Last active December 18, 2015 11:59
Learning Backbone.js
1. Listen to changes in the model can be implemented through the initialize() by the following format: this.on('change', callback_function). Listen to changes of a specific attribute can be done through this way too (just add in what attribute after change: change -> change:attr_name)
2. validation through Model.validate()
3. View does not contain the HTML markup. It contains the logic behind the presentation of the model's data to the user.
4. A view’s render() method can be bound to a model’s change() event, enabling the view to instantly reflect model changes without requiring a full page refresh.
5. el - a reference to the DOM element which every view has