Google自訂搜尋

Selected Category: Ruby console (17)

View Mode: Post List Post Summary

TWSMSR是一個搭配台灣簡訊(http://twsms.com)使用的簡訊傳送Library

TWSMSR的前身SMSender已經停止維護,將直接改由這個名稱與版本重新出發!

網址在:http://github.com/cfc/twsmsr

使用方式:

require 'twsmsr'
t = TWSMSR.new(username, password) # 帳號密碼請自己申請。
resp = t.send(tel, message) # 取得回應,如果resp是負的,表示有錯誤。如果resp大於0則那是Message ID,可以用t.query查詢狀態。
puts t.query # 查詢錯誤訊息
puts t.message_id # 取得Message ID
t.message_id = "123456" # 設定Message ID
puts t.query

 

有任何疑問歡迎寄信或留言,原始碼可上Github查看

Posted by zusocfc at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(74)

今天剛看到生活+釋出API(其實早就釋出了,API網址:http://tw.developer.yahoo.com/lifestyle_api.html)後,就開始把NetBeans打開來寫程式了XD
現在RubyForge的專案還沒開,倒是GoogleCode的已經開了(網址:http://code.google.com/p/yahoo-lifetype-api/)
程式是BSD授權,忘記怎樣包裝Gem檔,等到哪天想起來再包XD
程式使用範例(列出生活+的分類):
#!/usr/bin/env ruby
APPID = "NhYX9XjV34FPxdq7zD8T7wwc4QGI5VWu_48NHh03zbPYUfPpcWrpZzhcVDKFQsH9dQ--"
require 'lifetype'
require 'rexml/document'
include REXML

puts "獲取生活+類別中... 請稍後"
doc = Document.new(LifeType::Class.new(APPID).listClasses)
puts "獲取類別結束"
puts "類別總數: " + doc.get_elements("//rsp/ClassList")[0].attribute("count").to_s
puts "列出類別中... 請稍後"
doc.elements.each("//rsp/ClassList/Class") do |ele|
puts "ID: #{ele.attributes["id"]} -- #{ele.get_elements("Title")[0].text}"
end
puts "列出類別結束"
很簡單的就可以使用了,還有doc喔!
有Bug可以丟到GoogleCode的Issues或者丟到我信箱內
謝謝^^
Update: 2008/04/25 09:15
  現在可以從我的ShareMe抓0.3版了,請按我

Posted by zusocfc at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(423)

我把原始碼放在妹尬阿撲落得上面了
UTF-8ANSI碼兩種編碼版本
參考這篇文章撰寫的:[台灣論壇]  測試你的手機號碼是吉是凶
晚點再放上執行檔下載點...

Posted by zusocfc at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(443)

有鑒於某台主機的DNS常常掛掉.. 所以就寫了這個小程式..

while true
  `ps aux | grep named`.split("\n").each{|line|
    user, pid, cpu, mem, vsz, rss, tty, stat, start, time, *command = line.split("\s")
    flag = true if command[0] == "/usr/sbin/named"
    `/etc/init.d/named start` unless flag
  }
  sleep 300
end

Posted by zusocfc at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(382)

這個Library搭配http://www.twsms.com才可以使用喔!
有任何問題可以直接回這篇文章,或者寫信問我,我信箱是Gmail的,帳號跟我的這個部落格帳號一樣

我先說用法好了:
require 'twsms'
sms = TWSMS.new(username, password) # 帳號密碼
sms.sendSMS(mobile, message) # mobile: 目標手機號碼  message: 要傳的訊息
原始碼:
=begin
  == Information ==
  === Copyright: Apache 2.0
  === Author: CFC < zusocfc@gmail.com >
  === Prog. Name: TWSMS lib
  === Version: 0.1
  == Introduction ==
    TWSMS(Taiwan SMS)
    TWSMS is a SMS sender, it must use with http://www.twsms.com.
    There has no any library for the SMS system in Taiwan. So, I just coded this and release this version.
    This version just support for sending SMS.
  == Featured ==
   
  == Using TWSMS ==
    It just support for standalone class now.
    require it before you use.
  === Using TWSMS by standalone class
    require 'twsms'
    sms = TWSMS.new('username', 'password')
    sms.sendSMS('09xxxxxxxx', 'Hi, there! TWSMS library is so easy to use!')
    sms.sendSMS('09xxxxxxxx', 'Send SMS with options',
        :popup => 1,
        :type => "now",
        :mo => "Y")
=end

%w|uri cgi net/http|.each{|r| require r}

class TWSMS
  def initialize(username, password)
    @uname, @upwd = username, password
    @options = {
      :type => "now", # Sending type: now, vld
      :popup => "",
      :mo => "Y".upcase,
      :vldtime => "86400",
      :modate => "",
      :dlvtime => "",
      :wapurl => "",
      :encoding => "big5"
    }
   
    @errors = {
      -1.to_s.to_sym => "Send failed",
      -2.to_s.to_sym => "Username or password is invalid",
      -3.to_s.to_sym => "Popup tag error",
      -4.to_s.to_sym => "Mo tag error",
      -5.to_s.to_sym => "Encoding tag error",
      -6.to_s.to_sym => "Mobile tag error",
      -7.to_s.to_sym => "Message tag error",
      -8.to_s.to_sym => "vldtime tag error",
      -9.to_s.to_sym => "dlvtime tag error",
      -10.to_s.to_sym => "You have no point",
      -11.to_s.to_sym => "Your account has been blocked",
      -12.to_s.to_sym => "Type tag error",
      -13.to_s.to_sym => "You can't send SMS message by dlvtime tag if you use wap push",
      -14.to_s.to_sym => "Source IP has no permission",
      -99.to_s.to_sym => "System error!! Please contact the administrator, thanks!!"
    }
    @args = []
    @url ||= "http://api.twsms.com/send_sms.php?"
    @url += "username=" + @uname
    @url += "&password=" + @upwd
  end
 
  def sendSMS(mobile, message, opt={})
    @options[:mobile], @options[:message] = mobile, message
    @options.merge!(opt).each{|k, v| @args << k.to_s + "=" + CGI::escape(v.to_s)}
    @url += "&" + @args.join("&")
    self.chk_val
    chk_errors(Net::HTTP.get(URI.parse(@url)))
  end
 
  def chk_val
    @options[:dlvtime] = "" unless @options[:type] == "dlv"
    @options[:wapurl] = "" if @options[:type] != ("push" && "upush")
  end
 
  def chk_errors(resp)
    resp = resp.split("=")[1]
    if @errors.has_key?(resp.to_s.to_sym)
      puts "==========", "Error!! Message: ", @errors[resp.to_s.to_sym]
    else
      puts "==========", "Message has been send! Your message id is: " + resp.to_s
    end
  end
 
  protected :chk_val
end
晚點丟到Google Code Hosting上去...

Updated:
TWSMS on Google Code Hosting: http://code.google.com/p/twsms/
SMSender on RubyForge: http://rubyforge.org/projects/smsender/

Posted by zusocfc at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(680)

class Array
  def which_long?
    # Version 1.0
    # Coded by CFC < zusocfc  @ gmail . com >
    # PLEASE DO NOT REMOVE THE COMMENT OF THIS FUNCTION, THANKS A LOT.
    # Usage:
    #   ['a', 'ab', 'abc' 1234].which_long?
    #   => 1234
    self.size.times{|i| self[i]=self[i].to_s}
    max, long = 0, String.new
    self.each{|item| item.size > max ? (max = item.size; long = item) : next}
    long
  end
end

以上是原始碼,使用方式如下:

puts ['a', 'ab', 'abc', 1234].which_long?
=> 1234

授權還沒定,不過大家還是可以拿去使用:P
請不要拿掉註解.. 謝謝

Posted by zusocfc at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(400)

1 2 3