Skip to content

Instantly share code, notes, and snippets.

@ypxu
ypxu / aws_usage.py
Created December 23, 2011 22:59 — forked from KentaroAOKI/aws_usage.py
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'
@ypxu
ypxu / MajorityVoting.java
Created January 13, 2012 07:50
Java version of Majority Voting problem. http://goo.gl/d27jg
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 / gist:2325452
Created April 7, 2012 05:10
Palindrome Number
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 / gist:4998881
Last active December 14, 2015 00:29
// 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 / manifest.py
Last active June 20, 2016 06:58
Simple Text Protocol
# 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.
@ypxu
ypxu / zigzag_matrix.py
Created October 26, 2016 17:20
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
ypxu / pingpong.scala
Created April 1, 2017 00:17
Scala PingPong Example
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
### 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: