Skip to content

Instantly share code, notes, and snippets.

View dapangmao's full-sized avatar
🏠
Working from home

Dapangmao dapangmao

🏠
Working from home
View GitHub Profile

##1. 3Sum

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c) The solution set must not contain duplicate triplets. For example, given array S = {-1 0 1 2 -1 -4},

A solution set is:
root@bigcat:~# ./spark_ec2.py -k sas -i sas.pem --zone=us-east-1a launch test-cluster
Setting up security groups...
Searching for existing cluster test-cluster...
Spark AMI: ami-5bb18832
Launching instances...
Launched 1 slaves in us-east-1a, regid = r-259db6c8
Launched master in us-east-1a, regid = r-3e9db6d3
Waiting for AWS to propagate instance metadata...
Waiting for cluster to enter 'ssh-ready' state..........
@dapangmao
dapangmao / 白板.md
Last active August 29, 2015 14:15
白板

一下都是我面试的经验和教训,欢迎各位大牛指正或者补充

首先,要端正观念,写代码只是最后一步,是在对方完全理解了你的意图之后的最终表 述,所以,在写代码之前,一定要跟对方把你的意图表述清楚,一定不要在对方不懂你 的想法的情况下就开始写代码,大忌,大忌!

其次,写代码之前,大脑里面要有个大picture,不能想到哪儿写到哪儿。是你的大脑 在写代码,而不是白板上你的手在代码。你的手只是一个printer里面的喷头而已,是 它把你大脑里面的代码print到白板上,你的大脑才是控制那个喷头的芯片。所以,写 之前,你要看着那个白板打个腹稿,想想一下白板上可能有哪些代码,比如定义哪些变

data class;
    set sashelp.class;
    keep name age sex weight;
run;

proc sort;
    by weight;
run;
@dapangmao
dapangmao / post.md
Last active August 11, 2021 01:21
Solve the Top N questions in SAS/SQL

This is a following post after my previous post about SAS/SQL.

SAS's SQL procedure has a basic SQL syntax. I found that the most challenging work is to use PROC SQL to solve the TOP N (or TOP N by Group) questions. Comparing with other modern database systems, PROC SQL is lack of -

  • The ranking functions such as RANK() or the SELECT TOP clause such as
select TOP 3 * 
from class
;
@dapangmao
dapangmao / file.md
Last active August 29, 2015 14:12
Spark practice(4): malicious web attack

Suppose there is a website tracking user activities to prevent robotic attack on the Internet. Please design an algorithm to identify user IDs that have more than 500 activities within any given 10 minutes.

Sample.txt: AnonymousUserID TimeStamp ActivityCount

123    9:45am    10
234    9:46am    12
234    9:50am    20
456    9:53am    100
123    9:55am    33
456    9:56am    312
@dapangmao
dapangmao / README.md
Last active October 5, 2019 06:48
Deploy a MongoDB powered Flask app in 5 minutes

This is a quick tutorial to deploy a web service (a social network) by the LNMP (Linux, Nginx, MongoDB, Python) infrastructure on any IaaS cloud. The repo at Github is at https://github.com/dapangmao/minitwit-mongo-ubuntu.

####Stack The stack is built on the tools in the ecosystem of Python below.

Tool Name Advantage
Cloud DigitalOcean Cheap but fast
Server distro Ubuntu 14.10 x64 Everything is latest
WSGI proxy Gunicorn Manage workers automatically
@dapangmao
dapangmao / sql.md
Last active August 29, 2015 14:11
query text using SQL

In a class of a few children, use SQL to find those who are male and weight over 100.

class.txt (including Name Sex Age Height Weight)
Alfred M 14 69.0 112.5 
Alice F 13 56.5 84.0 
@dapangmao
dapangmao / parents.md
Last active August 29, 2015 14:11
find grandchild-grandparent pairs from chid-parent pairs

Sample.txt (the first word is child; the second word is parent)

Tom Lucy
Tom Jack
Jone Lucy
Jone Jack
Lucy Mary
Lucy Ben
Jack Alice