Skip to content

Instantly share code, notes, and snippets.

Avatar

Yingpeng Xu ypxu

  • California
View GitHub Profile
View gist:5748a9a262f5dd2e0b3d4b1102dfbeca
### Keybase proof
I hereby claim:
* I am ypxu on github.
* I am yingxu (https://keybase.io/yingxu) on keybase.
* I have a public key ASA5kc7FdnEa48Gn0Tb_gP7sDLO77quXivCdiuSaqHDELgo
To claim this, I am signing this object:
@ypxu
ypxu / pingpong.scala
Created Apr 1, 2017
Scala PingPong Example
View pingpong.scala
import akka.actor.{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
ypxu / zigzag_matrix.py
Created Oct 26, 2016
Output Matrix in Zigzag order
View zigzag_matrix.py
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
ypxu / manifest.py
Last active Jun 20, 2016
Simple Text Protocol
View manifest.py
# a - j, Z, M,K,P,Q
"""
Thoughts
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
this.$(this.selectItemsTag).select2({
placeholder:"Enter an items",
multiple:true,
minimumInputLength:1,
maximumSelectionSize:200,
initSelection : function (element, callback) {
var data = [];
@ypxu
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
ypxu / MajorityVoting.java
Created Jan 13, 2012
Java version of Majority Voting problem. http://goo.gl/d27jg
View MajorityVoting.java
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
ypxu / aws_usage.py
Created Dec 23, 2011 — forked from KentaroAOKI/aws_usage.py
A script to query the AWS usage reports programmatically.
View aws_usage.py
#!/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'