This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def main | |
| # urls is a hash containing url to retrieve statuses of items | |
| get_csv(urls, items) { |response, item| | |
| item_results = CSV.parse_line(response.body) | |
| item.setStatus(item_results[0]) | |
| } | |
| end | |
| def process_response(urls, items) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ftplib | |
| from ftplib import FTP | |
| buffer = '\x41' * 400 | |
| try: | |
| ftp = FTP('127.0.0.1') | |
| ftp.login(user, password) | |
| ftp.transfercmd("command" + buffer) | |
| print 'xxx' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'mechanize' | |
| require 'fastercsv' | |
| def get_all_option_values(page, attr_name) | |
| page.search("[name=#{attr_name}]").search("option").map do |opt| | |
| option_value = opt.attribute("value").value | |
| [option_value, opt.text.strip.gsub(/\302\240\302\240/, '')] if option_value && option_value.length > 0 | |
| end.compact | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'mechanize' | |
| require 'benchmark' | |
| agent = Mechanize.new | |
| # however, this fetch already spend around 2 seconds. one http request response. | |
| page = agent.get('http://www.ufood.com.hk/search/search.action?name=&distIds=4,10,11,3,5,8,6,7,2,1,9,12,13,14,15,18,16,17,19,20,21,22,23,24,25,26,33,34,27,35,32,30,29,28,31&ftIds=') | |
| Benchmark.bm do |b| | |
| # search by tag name and class 10.470000 0.040000 10.510000 ( 11.149709) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test "not allow to update state after account reconciliation" do | |
| # get fixture | |
| account = accounts(:fresh) | |
| # submit and expect no errors | |
| post :waive_fee, :id => account.id | |
| assert_nil flash[:error] | |
| post :add_fee, :id => account.id | |
| assert_nil flash[:error] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define :generate_ssh_keys, :user_account => nil do | |
| username = params[:user_account] | |
| raise ":user_account should be provided." if username.nil? | |
| Chef::Log.debug("generate ssh skys for #{username}.") | |
| execute "generate ssh skys for #{username}." do | |
| user username | |
| creates "/home/#{username}/.ssh/id_rsa.pub" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'active_record' | |
| require 'yaml' | |
| dbconfig = YAML::load(File.new(File.join(File.dirname(__FILE__), "../../config/database.yml"))) | |
| ActiveRecord::Base.establish_connection(dbconfig["development"]) | |
| class StockDailyPrice < ActiveRecord::Base | |
| def initialize(stock_values, stock_no = "") | |
| super() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def logger | |
| @logger ||= Logger.new(File.new("data_loader.log"),3,5*1024*1024) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cron "housekeep application log files" do | |
| user "housekeeper" | |
| # mailto "[email protected]" | |
| # 00:01 every night | |
| hour "0" | |
| minute "1" | |
| # clean up logs older than 30 days | |
| command "/find ~/log/application-*.log.tar.gz -mtime +30 -exec rm {} \;" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # gem "prawn", "0.8.4" | |
| # Sometime there is no enough space for the last table row when it reaches the end of page | |
| Prawn::Document.generate("text_group_overflow_question.pdf") do |pdf| | |
| add_page_break_if_overflow(pdf) do |pdf| | |
| # generating table here | |
| # ... | |
| end | |
| end |
OlderNewer