分类: tech

  • IronRuby一些小技巧

    操作excel

     1: require "Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 

     2:  

     3: include Microsoft::Office::Interop::Excel

     4: excel = ApplicationClass.new

     5: excel.Visible = true

     6: workbook = excel.Workbooks.Add()

     7: worksheet = workbook.Worksheets.Add()

     8: worksheet.Name = "aaaaa" 

     9:  

     10: cell1 = worksheet.Cells(1,1)

     11: cell1.Value = 42

    如何获得assembly的strong name?

     1: load_assembly 'Microsoft.Office.Interop.Excel'

     2:  

     3: System::AppDomain.current_domain.get_assemblies.each{|x| puts x};

    RPC 解决方案(http://www.ruby-forum.com/topic/206314

    Very CLR centric:

    You can create a proxy to your webservice using visual studio, compile to a dll and use the proxy from your ruby code.

    CLR centric:

    You can use System.Net.HttpWebRequest to make the request and System.Xml.XmlDocument to parse the response

    Very Ruby centric:

    Use Net::HTTP to perform the request and REXML to parse the response

  • IronRuby试玩

    IronRuby下载最新版本解压,然后把目录加入系统Path。

    IronRuby使用Sinatra

    1)igem install sinatra –no-rdoc –no-ri

    2) 应该提示rack和sinatra都安装完毕

    3)写代码如下:

     1: require 'rubygems'

     2: require 'sinatra' 

     3: get '/' do

     4: "My machine name is #{System::Environment::machine_name}"

     5: end

    保存为mysinatra1.rb

    4) 运行 ir mysinatra1.rb,应该提示类似pid=xxxx port=4567,打开浏览器,输入http://localhost:4567/ 就可以看到期望的信息了。

    注意,在我测试过程中,最新版本下,不需要对sinatra做任何patch,跟ironruby官网提到的不一样。

    IronRuby使用Rails,参考http://www.ironruby.net/Documentation/Real_Ruby_Applications/Rails

    1)安装 "igem install rake rails activerecord-adonet-sqlserver –no-rdoc –no-ri"

    2)如果自己测试,可使用sqlite3-ironruby,"igem install sqlite3-ironruby –no-ri –no-rdoc”

    3)建立一个IronRuby rail程序, "ir -S rails IronFirst"

    4)修改config/environment.rb,可以看到有类似的代码,改成 config.gem "sqlite3-ironruby", :lib => "sqlite3" ,使用sqlserver有另外的修改方式,大家自己看网页吧。

    5)ir script\generate scaffold post title:string body:text published:boolean

        ir -S rake db:migrate

    6)ir script\server

    这时候可以看到http://localhost:3000 是rails的默认界面,进入http://localhost:3000/posts 可以进行添删改操作。不过我测试,默认下不支持中文,应该是要修改一些参数才行。

    all done.

  • 一个内部局域网投票程序的初步设计

    最近准备学习dotnet,要有一些代码练练手。看好了sliverlight或者wpf,毕竟是下一代显示技术。

    基本设想如下,客户端运行程序,读取数据,动态生成投票(或者是survey)界面,运行,保存,然后将数据传回服务器端。

    技术问题不算多,也有,比如sliverlight其实是没法直接连接数据库的,这个从安全角度也说得通。所以就要引入WCF或者RIAService技术,又多了一层曲线要学。

    如何让读取保存数据过程更简单,容易实现?我想到了ironpython。

    下载了最新版本的ironpython,搜索一下xmlrpc就能找到这篇文章:

    http://www.ibm.com/developerworks/library/ws-pyth10.html

    其中服务器代码如下:

    import calendar, SimpleXMLRPCServer

    #The server object
    class Calendar:
        def getMonth(self, year, month):
            return calendar.month(year, month)

        def getYear(self, year):
            return calendar.calendar(year)

    calendar_object = Calendar()
    server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
    server.register_instance(calendar_object)

    #Go into the main listener loop
    print "Listening on port 8888"
    server.serve_forever()

    客户端代码如下

    import xmlrpclib

    server = xmlrpclib.ServerProxy("http://localhost:8888")

    month = server.getMonth(2002, 8)
    print month

    主要是python的标准库实现了xmlrpc机制,而WCF技术说白了,也就是类似XMLRPC这样的remote process calling技术,换个马甲我就不认识你了么?

    应该也可以通过dotnet framework,没那兴趣继续研究,就到这里吧。

    ironpython应用于WPF的文章也很多,有机会试验了以后写出来。

    image

  • Windows桌面开发者的必备软件

    如果你新安装好了一台WindowsXP或者Windows7的机器,作为一个开发人员,我建议安装下面这些软件:

    1,WinMerge.

    http://winmerge.org/

    2, Lua for windows,或者Python或者Ruby,选择一个你喜欢的脚本语言。LuaForWindows还自带了一个Scite编辑器,节省了找一个程序员相关编辑器的步骤。

    http://luaforwindows.luaforge.net/

    3,7-zip,不需要安装winzip或者winrar了

    http://www.7-zip.org/

    4,Sysinternals套件,windows开发必备。

    http://technet.microsoft.com/en-us/sysinternals/default.aspx

    5,Windbg,windows调试必备。

    http://www.microsoft.com/whdc/Devtools/Debugging/default.mspx

    6,FileZilla,开源的ftp软件。

    http://filezilla-project.org/

    7,Visual Studio2008 express,微软系的同学必须要的。当然,你应该很容易搞到更高级的版本。如果不玩dotnet那些,可以下载个VC++6.0,足够用了。

    http://www.microsoft.com/express/Downloads/#webInstall

    Java系的朋友,自有选择,不多废话。

    8,Debug Diagnostic Tool,检查memory leak很好用。

    http://www.microsoft.com/downloadS/details.aspx?FamilyID=28bd5941-c458-46f1-b24d-f60151d875a3&displaylang=en

    9,bitnami stacks,如果你搞什么php,ruby,python,mysql之类的web开发,这里面的集成安装包必有一款适合你。不想安装的还可以下载vmware镜像文件。

    http://bitnami.org/stacks

    10,daemon-tools,虚拟光驱软件。

    11,文本编辑器,notepad++或者gVim都不错。

    http://portableapps.com/apps

    12,SSH软件推荐putty,破墙必备。

    http://portableapps.com/apps/internet/putty_portable

    13,VNC类的软件可以用这个

    http://portableapps.com/apps/utilities/teamviewer_portable

    也可以用QQ或者netmeeting之类的,也是必备。

    14,Picpick,抓屏软件,非常推荐。

    http://picpick.wiziple.net/

    15,版本管理工具,可以用subversion或者git。github算是个不错的选择。我经常把小代码片段贴到gist中。其中visualsvn有免费服务器程序下载。

    http://www.visualsvn.com/

    http://subversion.tigris.org/

    http://github.com/guides/using-git-and-github-for-the-windows-for-newbies

    16,如果搞网络相关开发,可以下载抓包工具wireshark(原名ethereal)。

    http://www.wireshark.org/

    http也可以试试这个软件

    http://www.fiddler2.com/fiddler2/ 

    17,VMWare虚拟机,最好搞一个,里面装上Debian,玩玩Linux,另外装个干净的windowsXP,压缩起来备用,测试中经常会用到。