本文主要是介绍知乎周源微信_每周源代码29-Ruby和Shoes和第一个Ruby病毒,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

知乎周源微信
I was in Norway last week at the Norwegian Developers Conference, so I'm afraid the Weekly Source Code is the bi-weekly source code this month. It's amazing how international travel can really slow a body down. This trip just obliterated me. I'm slowly coming back to the world of the living, though.
上周我在挪威开发者大会上在挪威,所以恐怕每周源代码是本月的每两周一次源代码。 令人惊讶的是,国际旅行真的可以使身体慢下来。 这次旅行使我丧胆。 不过,我正在慢慢回到生活世界。
I've been getting more and more interested in how folks extend their applications using plugins and things. In my new ongoing quest to read source code to be a better developer, Dear Reader, I present to you twenty-ninth in a infinite number of posts of "The Weekly Source Code."
我对人们如何使用插件和事物扩展其应用程序越来越感兴趣。 在我不断寻求阅读源代码以成为更好的开发人员的过程中,亲爱的读者,我在无限数量的“每周源代码”帖子中向您展示第二十九位。
This week's source is a clever "ClickOnce"-style hack for Ruby. It's cool because it brings together a number of technologies into a very clean end-user experience. The intent is to make the running of a Ruby GUI Application effortless, and it works and it's brilliant on several levels. Thanks to Sam Saffron for pointing me to it!
本周的消息来源是针对Ruby的聪明的“ ClickOnce”风格黑客。 之所以酷,是因为它将多种技术融合在一起,形成了非常干净的最终用户体验。 目的是使Ruby GUI应用程序的运行轻松自如,并且可以正常运行,并且在多个级别上都非常出色。 感谢Sam Saffron为我指出这一点!
To start out, it's a hack says the author why the lucky stiff (or "_why" for short), so it's very early and there's bugs. You can check out the code on GitHub: http://github.com/why/shoes/tree/master or clone the whole tree using git via "git clone git://github.com/why/shoes.git
"
首先,作者说了一个hack的原因,为什么幸运的僵硬(或简称为“ _why”),所以现在还很早,并且存在错误。 您可以在GitHub上检出代码: http git clone git://github.com/why/shoes.git
或通过git通过“ git clone git://github.com/why/shoes.git
”克隆整个树
鞋类(Shoes)
Ruby is a very aesthetically (to me) pleasing and flexible language. Shoes is a GUI Toolkit for making Windowing Applications using Ruby. I mentioned it back in TWSC12. Shoes is legendary for a number of reasons, but above all, it has the greatest API documentation in the history of all software documentation. The main book on Shoes Development called "nobody knows shoes" is fantastic. Even Chris Sells likes it!
在我看来,Ruby是一种非常美观且灵活的语言。 Shoes是用于使用Ruby制作窗口应用程序的GUI工具包。 我在TWSC12中提到了它。 鞋子因许多原因而具有传奇色彩,但最重要的是,它具有所有软件文档历史上最出色的API文档。 关于鞋类开发的主要书籍“没人知道鞋子”真是太棒了。 甚至Chris Sells也喜欢!
Here's part of an example phone book application written in Ruby and Shoes):
这是用Ruby和Shoes编写的示例电话簿应用程序的一部分):
Shoes.app :width => 320, :height => 350 do
stack :margin => 40 do
stack :margin => 10 do
para "Name"
@name = list_box :items => ["Yes, please!", "NO. No thankyou."]
end
stack :margin => 10 do
para "Address"
@address = edit_line
end
stack :margin => 10 do
para "Phone"
@phone = edit_line
end
stack :margin => 10 do
button "Save" do
Shoes.p [@name.text, @address.text, @phone.text]
end
end
end
end
It feels a lot like Tcl/Tk or Rebol. It'll be interesting to see if someone writes a mainstream application that is non-trivial. Shoes works on XP, Vista, MacOSX and Linux. Do note that you'll need to right click and run it as Administrator on Vista as _why hasn't put in an elevation prompt yet. You'll need Admin to do the initial bootstrap install.
感觉很像Tcl / Tk或Rebol。 看看是否有人编写了一个不平凡的主流应用程序会很有趣。 Shoes可以在XP,Vista,MacOSX和Linux上运行。 请注意,由于_why尚未出现在提升提示中,因此您需要右键单击并以管理员身份在Vista上运行它。 您需要Admin来进行初始引导安装。
However, in order to get Shoes to work, before today, you had to install Ruby, then get the Shoes libraries installed, usually via a gem. Then you'd need to run your app via ruby.exe yourapp.rb or a shortcut you'd setup. The second comment on _why's blog post announcement says it all:
但是,为了使Shoes正常工作,在今天之前,您必须安装Ruby,然后通常通过gem来安装Shoes库。 然后,您需要通过ruby.exe yourapp.rb或您设置的快捷方式运行您的应用程序。 关于_why博客文章公告的第二条评论说明了一切:
"Wow, this is super. We can actually give our apps to other people now :)"
“哇,这太好了。我们实际上可以现在将我们的应用程序提供给其他人:)”
Here's an explanation from _why on how the Shoes "bootstrapper" (my word) works:
这是_why的解释,说明鞋的“ bootstrapper”(我的话)是如何工作的:
If you poke around with a hex editor inside Windows’ PE binary format, you’ll find an .rsrc section at the end of the file which contains the icons and dialog boxes. I insert the Ruby script into this mess.binj = Binject::EXE.new("blank.exe") binj.inject("SHOES_FILENAME", "simple-accordion.rb") File.open("simple-accordion.rb") do |f|binj.inject("SHOES_PAYLOAD", f) end binj.save("accordion.exe")
如果您使用Windows PE二进制格式的十六进制编辑器来查看,您将在文件末尾找到一个.rsrc节,其中包含图标和对话框。 我将Ruby脚本插入这个烂摊子。binj = Binject::EXE.new("blank.exe") binj.inject("SHOES_FILENAME", "simple-accordion.rb") File.open("simple-accordion.rb") do |f|binj.inject("SHOES_PAYLOAD", f) end binj.save("accordion.exe")
Fantastic hack. He shoves the Ruby script into a Windows Resource! He does the same thing for DMG (Disk Images) on Mac OSX, so you can create Ruby scripts that are portable to these two platforms.
很棒的骇客。 他将Ruby脚本推送到Windows资源中! 他在Mac OSX上对DMG(磁盘映像)执行相同的操作,因此您可以创建可移植到这两个平台的Ruby脚本。
When it runs, it checks for the existence of Shoes on your system. It's in C:\Program Files (x86)\Common Files\Shoes\. If Shoes (which includes a private copy of Ruby) is not there, it's downloaded and installed, and then your app runs. Bam, one-click cross-platform GUIs.
当它运行时,它将检查系统上是否存在Shoes。 它在C:\ Program Files(x86)\ Common Files \ Shoes \中。 如果不存在Shoes(包括Ruby的私人副本),则将其下载并安装,然后运行您的应用程序。 Bam,一键式跨平台GUI。
I'm not clear what the security ramifications are. Well, I am. I suspect there is no security that isn't already provided by the host operating system. Once you're running, the Ruby script has full control to do whatever it likes, so I suppose someone could write a malicious program just as they could write a malicious .NET app if they liked.
我不清楚安全后果是什么。 好吧,我。 我怀疑主机操作系统没有提供任何安全性。 一旦运行,Ruby脚本就可以完全控制自己喜欢做的事情,所以我想有人可以编写恶意程序,就像他们愿意编写恶意.NET应用程序一样。
You can package your apps just by running shoes --package and you'll get this dialog. You can chose to include Shoes and Ruby inside the resulting EXE if you like.
您可以仅通过跑步鞋--package来打包应用程序,然后会出现此对话框。 如果愿意,您可以选择在生成的EXE中包含Shoes和Ruby。

Shoes also supports custom "Widgets." For example, here's a custom Speedometer control.
鞋子还支持自定义“小部件”。 例如,这是一个自定义的Speedometer控件。
The code for the entire app, including the custom control is this:
整个应用程序(包括自定义控件)的代码如下:
class Speedometer < Widget
attr_accessor :range, :tick, :position
def initialize opts = {}
@range = opts[:range] || 200
@tick = opts[:tick] || 10
@position = opts[:position] || 0
@cx, @cy = self.left + 110, self.top + 100
nostroke
rect :top => self.top, :left => self.left,
:width => 220, :height => 200
nofill
stroke white
oval :left => @cx - 50, :top => @cy - 50, :radius => 100
(ticks + 1).times do |i|
radial_line 225 + ((270.0 / ticks) * i), 70..80
radial_line 225 + ((270.0 / ticks) * i), 45..49
end
strokewidth 2
oval :left => @cx - 70, :top => @cy - 70, :radius => 140
stroke lightgreen
oval :left => @cx - 5, :top => @cy - 5, :radius => 10
@needle = radial_line 225 + ((270.0 / @range) * @position), 0..90
end
def ticks; @range / @tick end
def radial_line deg, r
pos = ((deg / 360.0) * (2.0 * Math::PI)) - (Math::PI / 2.0)
line (Math.cos(pos) * r.begin) + @cx, (Math.sin(pos) * r.begin) + @cy,
(Math.cos(pos) * r.end) + @cx, (Math.sin(pos) * r.end) + @cy
end
def position= pos
@position = pos
@needle.remove
append do
@needle = radial_line 225 + ((270.0 / @range) * @position), 0..90
end
end
end
Shoes.app do
stack do
para "Enter a number between 0 and 100"
flow do
@p = edit_line
button "OK" do
@s.position = @p.text.to_i
end
end
@s = speedometer :range => 100, :ticks => 10
end
end
It's about 24 megs of libraries on disk when you're done, but you've got multimedia support and a lot of great library support in that space, not to mention a copy of Ruby itself. The download is only 2.5M bare or 6.8M with Video support.
完成后,磁盘上大约有24兆的库,但是在该空间中,您已经获得了多媒体支持和很多强大的库支持,更不用说Ruby本身了。 仅有视频支持,下载仅需250万裸机或6.8M。
I think it'd be great to build a Twitter Client using Shoes. The race is on! Hopefully we'll be able to get a Twitter Client done before some schmuck writes a Ruby Shoes virus. I for one, will be keeping the Ruby Shoes virus I wrote to myself. Well, not really a virus as it's a self propagating annoyance. But still. :)
我认为使用Shoes构建一个Twitter Client非常好。 比赛开始了! 希望我们能够在某些schmuck编写Ruby Shoes病毒之前完成一个Twitter Client。 首先,我将保留我写给自己的Ruby Shoes病毒。 嗯,这不是一种病毒,因为它是一种自我传播的烦恼。 但是还是。 :)
It'll be fun to watch how this evolves. I hope there will be a clean upgrade process. If you want to try running your first Ruby/Shoes app, then run this EXE if you've got Windows or this DMG if you're on a Mac to see a basic demo application, but more importantly, to experience in the installer/bootstrapping process.
看着它如何演变会很有趣。 我希望会有一个干净的升级过程。 如果您想尝试运行第一个Ruby / Shoes应用程序,那么如果您使用的是Windows,请运行此EXE;如果您使用的是Mac,则请运行此DMG ,以查看基本的演示应用程序,但更重要的是,要体验安装程序/引导过程。
翻译自: https://www.hanselman.com/blog/the-weekly-source-code-29-ruby-and-shoes-and-the-first-ruby-virus
知乎周源微信
这篇关于知乎周源微信_每周源代码29-Ruby和Shoes和第一个Ruby病毒的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!