ruby

Context sensitive auto-completion using PowerShell, PowerTab and GIT

Powertab is an Awesome PowerShell TabExpansion extension. It extends the default PowerShell autocompletion and shows the results like:

image

The best part is that it is easily customizable.

One way to customize it is by editing it Tab Expansion database file which is located in your powershell profile directory:

TabExpansion.xml

› Continue reading

Monday, October 13th, 2008 GIT, powershell, ruby, vista, windows 5 Comments

Creating a chat application using Socket in Silverlight

Here I will explain how to communicate with the server using the Socket class. The socket class allows Asynchronous communication between the client and server. This application will show how to share data in real-time in two different browser windows using Silverlight.

This application will contain two parts:

  1. Server application using Ruby.
  2. Client application using C# in Silverlight.
Creating the server application:

Making a multi-threaded server application in ruby is really easy and that is the reason I chose Ruby to create the server in least amount of time possible.

   1: require 'socket'
   2:  
   3: HOST = 'localhost'
   4: PORT = 4505
   5:  
   6: server = TCPServer.new(HOST, PORT)
   7:  
   8: # array to store all the active connections
   9: sessions = []
  10: while (session = server.accept)
  11:   # push the current session(socket) in the array
  12:   sessions << session
  13:   # initialize a new thead for each connection
  14:   Thread.new(session) do |local_session|
  15:     # each time a client sends some data send it to all the connections
  16:     while(true)
  17:       data = local_session.gets
  18:       sessions.each do |s| 
  19:         begin
  20:           s.puts data
  21:         rescue Errno::ECONNRESET
  22:           # an exception is raised, that means the connection to the client is broken
  23:           sessions.delete(s)
  24:         end
  25:       end
  26:     end
  27:   end
  28: end

 

Here is the pastie.

Save this file as chat_server.rb

› Continue reading

Using Flex with Ruby on Rails

This is the second blog post in a series of three posts comparing Flex with Silverlight. In my previous post I demonstrated how to integrate a scaffolded Rails application with Silverlight. Here I will be showing the same with Flex. The steps needed to create the Rails application are also mentioned here.

 

Creating a new Flex project:

Open Flex builder and create a new Flex project.

image

Leave all the options to default and click Finish. A blank project is now created for you.

› Continue reading

Wednesday, March 26th, 2008 adobe, flex, mxml, rails, ruby, ruby on rails, silverlight, xaml 3 Comments

Using Silverlight with Ruby on Rails

In this post I will be showing a really simple example of creating a Silverlight frontend for a Rails backend. This is what I think will be a three part series comparing Silverlight with Flex.

The steps will be:

  1. Creating a Rails application.
  2. Creating a frontend for it in silverlight.
  3. Creating a frontend for it in Flex.
  4. Comparing the approaches taken in both the frontends.

I will try to keep changes in the backend Rails application to a minimum.

› Continue reading

Wednesday, March 26th, 2008 C#, adobe, crud, flex, microsoft, mxml, rails, ruby, ruby on rails, silverlight, xaml 4 Comments

Sudo for Vista

The following ruby script when given any executable file path as the argument runs it in administrative mode.

   1: require 'Win32API'
   2:  
   3: def shell_execute(process_name)
   4:     process = ''
   5:     process.replace(process_name)
   6:     se = Win32API.new("shell32", "ShellExecute", ['P','P','P','P','P','I'], 'I')
   7:     se.Call(nil,"runas",process,nil,nil,5)
   8: end
   9:  
  10: shell_execute(ARGV[0])

 

In Vista you can do the same by right clicking on the file and selecting “Run as Administrator” but this script allows you to run a process in admin mode using the command line.

The ShellExecute function resides in the shell32.dll and is documented here.

By just giving “runas” as the second parameter to the function the process is executed in the administrative mode.

Wednesday, November 28th, 2007 ruby, security, software, vista 1 Comment