Skip to content

Instantly share code, notes, and snippets.

@feiskyer
feiskyer / 12306AutoSubmit.user.js
Created January 10, 2012 13:52
12306 Auto Submit
/*
12306 Auto Submit => A javascript snippet to help you auto submit.
Copyright (C) 2011 Kevintop
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes 12306.user.js
@feiskyer
feiskyer / 12306AutoSubmit.user.js
Created January 10, 2012 13:53
12306 Auto Submit
/*
12306 Auto Submit => A javascript snippet to help you auto submit.
Copyright (C) 2011 Kevintop
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes 12306.user.js
@feiskyer
feiskyer / 12306.user.js
Created January 16, 2012 03:18 — forked from quietlynn/12306.user.js
12306 Auto Query => A javascript snippet to help you book ticket
/*
12306 Auto Query => A javascript snippet to help you book tickets online.
Copyright (C) 2011-2012 Jingqin Lynn
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes Sizzle.js
@feiskyer
feiskyer / gist:1964710
Created March 3, 2012 06:35
Berkeley SaaS class HW1 fun with strings
#!/usr/bin/ruby
def palindrome?(string)
string.downcase!
string=string.gsub(/[^a-z]+/,'') # 正则表达式替换
string==string.reverse
end
p palindrome?('thissiht')
@feiskyer
feiskyer / gist:1964724
Created March 3, 2012 06:36
Berkeley SaaS class HW1 Rock-Paper-Scissors
class WrongNumberOfPlayersError < StandardError ; end
class NoSuchStrategyError < StandardError ; end
def compare_game?(game)
return (game[0][1] + game[1][1]) =~ /rs|sp|pr|rr|ss|pp/i
end
def rps_game_winner(game)
strategy=["r","p","s"]
raise WrongNumberOfPlayersError unless game.length == 2
@feiskyer
feiskyer / gist:1964733
Created March 3, 2012 06:40
Berkeley SaaS class HW1 Part 3: anagrams
def anagrams?(w1, w2)
w1.downcase.split('').sort == w2.downcase.split('').sort
end
def combine_anagrams(words)
ret=[]
while words.length>0 do
i=0
temp=[words[i]]
j=i+1
@feiskyer
feiskyer / gist:1964748
Created March 3, 2012 06:46
Berkeley SaaS class HW1 Part 4: Basic OOP
# (a) Create a class Dessert with getters and setters for name and calories. Define
# instance methods healthy?, which returns true if a dessert has less than 200
# calories, and delicious?, which returns true for all desserts.
#
# (b) Create a class JellyBean that extends Dessert, and add a getter and setter for
# flavor. Modify delicious? to return false if the flavor is black licorice (but delicious?
# should still return true for all other flavors and for all non-JellyBean desserts).
class Dessert
attr_accessor :name
@feiskyer
feiskyer / HW1_part5.rb
Created March 3, 2012 06:49
Berkeley SaaS class HW1 Part 5: advanced OOP with some metaprogramming
# advanced OOP with some metaprogramming
class Class
def attr_accessor_with_history(attr_name)
attr_name = attr_name.to_s
# getter
attr_reader attr_name
attr_reader attr_name+"_history"
# 为类动态添加方法
class_eval %{
@feiskyer
feiskyer / Srm144Lottery.cxx
Created March 7, 2012 13:00 — forked from anisaraf/Srm144Lottery.cxx
Solution to TopCoder:SRM144 Lottery
#include <sstream>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
unsigned long long factorialDivide(int num, int den){
unsigned long long rValue = 1;
@feiskyer
feiskyer / isPrime.py
Created April 22, 2012 04:10
isPrime
def isPrime(n):
n=abs(n)
if n<=1:
return False
if n==2:
return True
if not n&1:
return False
i=3
while i*i<=n: