Skip to content

Instantly share code, notes, and snippets.


Yingpeng Xu ypxu

  • California
View GitHub Profile
View gist:5748a9a262f5dd2e0b3d4b1102dfbeca
### Keybase proof
I hereby claim:
* I am ypxu on github.
* I am yingxu ( on keybase.
* I have a public key ASA5kc7FdnEa48Gn0Tb_gP7sDLO77quXivCdiuSaqHDELgo
To claim this, I am signing this object:
ypxu / pingpong.scala
Created Apr 1, 2017
Scala PingPong Example
View pingpong.scala
import{Actor, ActorRef, ActorSystem, Props}
case object PingMessage
case object PongMessage
case object StartMessage
case object StopMessage
class Ping(pongRef: ActorRef) extends Actor {
var count = 0
ypxu /
Created Oct 26, 2016
Output Matrix in Zigzag order
class Solution(object):
def flatten(self, matrix):
if not matrix:
return []
m, n = len(matrix), len(matrix[0])
delta_move = [(-1, 1), (1, -1)] # right_up, left_down
delta_pivot = [(1, 0), (0, 1)] # down, right
result = []
i, j = 0, 0
ypxu /
Last active Jun 20, 2016
Simple Text Protocol
# a - j, Z, M,K,P,Q
Consider the message a tree, walk the message until we meet the valid
considition which there's no more charactors.
When we encouter a - j, we substract one from the message. When we see
Z, we look for next valid message, when we counter M,K,P,Q, we look
for two valid message.
View gist:4998881
// use case sample
placeholder:"Enter an items",
initSelection : function (element, callback) {
var data = [];
ypxu / gist:2325452
Created Apr 7, 2012
Palindrome Number
View gist:2325452
public class PalindromeNumber {
public static boolean checkifPalindrome(int num) {
if (num < 0) {
return false;
int div = 1;
while (num / div >= 10) {
div = div * 10;
ypxu /
Created Jan 13, 2012
Java version of Majority Voting problem.
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MajorityVoting {
public static String checkForWinner(List<String> votes) {
String winner = "Nobody";
String[] votesArr = votes.toArray(new String[votes.size()]);
ypxu /
Created Dec 23, 2011 — forked from KentaroAOKI/
A script to query the AWS usage reports programmatically.
#!/usr/bin/env python
A script to query the Amazon Web Services usage reports programmatically.
Ideally this wouldn't exist, and Amazon would provide an API we can use
instead, but hey - that's life.
Basically takes your AWS account username and password, logs into the
website as you, and grabs the data out. Always gets the 'All Usage Types'