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.
Periodically changing desktop wallpaper using Ruby
Here is small ruby script that picks up a random image from a given folder and sets it as the desktop wallpaper.
1: require 'Win32API'
2:
3: SPI_SETDESKWALLPAPER = 20
4: SPIF_SENDCHANGE = 0x2
5: SOURCE_FOLDER = "C:\\Users\\Gaurav\\Pictures\\Best\\"
6:
7: files = Dir.entries(SOURCE_FOLDER) - [".", ".."]
8: file = files[rand(files.length)]
9:
10: systemParametersInfo = Win32API.new("user32","SystemParametersInfo",["I", "I", "P", "I"],"I")
11: p systemParametersInfo.call(SPI_SETDESKWALLPAPER, 1, SOURCE_FOLDER + file, SPIF_SENDCHANGE)
The constant SOURCE_FOLDER can be changed to point at the folder which contain all your wallpaper and the script then randomly chooses a wallpaper from the collection.
You can also set your task scheduler to run this script automatically after a fixed interval so that your desktop wallpaper keeps changing.
Here is the pastie.
Renaming MP3 files based on ID3 tag information
Here is a neat little trick that I often find useful for renaming mp3 files with wrong names and correct tag titles. Just run this ruby script in the directory where you have stored your songs and it will read the tag title and rename the current file using it.
1: require "rubygems"
2: require "id3lib"
3: require "fileutils"
4:
5: files = `dir /s /b *.mp3`
6:
7: files.split("\n").each do |file|
8: dir = File.dirname(file)
9: tag = ID3Lib::Tag.new(file)
10: new_name = tag.title.gsub("00",'') if tag.title
11: FileUtils.move(file, File.join(dir, new_name + ".mp3")) if new_name and !new_name.empty? rescue nil
12: end
This script requires id3lib gem for ruby which can be installed simply by running the command:
gem install id3lib-ruby
One thing to notice in the script is that currently it works only on windows, but only with a little modification it can be made to work on other OSes as well (The only change I guess will be in the 5th line).
Here is the pastie link for this code.
Windows XP SP3 boasts speed boost, testers claim
According to this link http://www.computerworld.com/action/article.do?command=printArticleBasic&articleId=9048658 SP3 has made XP significantly faster.
Like users needed another reason for not migrating to VISTA.
10 of my favorite softwares
I like to explore softwares. I usually install a lot of softwares on my system. I thought that I should make a list of my favorite softwares and share it with everybody. All of there softwares are either open-source or free.
1. Autohotkey(FOSS): It manages your hotkeys globally and allows you to create complex actions based on the keys pressed. Its actually got its own scripting language which is rather easy to learn. Just write a script in a file with extension .ahk and double click the file to execute it.
With AutoHotKey you can:
- manage processes, windows and control both keyboard and mouse.
- create macros saving you precious keystrokes.
- re-map keys and buttons on your keyboard and mouse.
I have been using AutoHotKey for quite a while now and I use it to manage my code snippets, have consistent hotkeys across applications and creating macros like googling the selected text in any application. The following is the AutoHotKey script for it:
1: #g::
2: Send ^c
3: Run http://www.google.co.in/search?hl=en&q=%clipboard%
4: return
So by using this script whenever I press Ctrl+G the script will open a browser and search the selected text in google. Nice isn’t it?
Blogroll
Recent Posts
- Autocompleting ssh, rake, cap command parameters using PowerShell
- Using RubyAmf for creating a CRUD application in Rails
- Multiple ways to open PowerShell in the current Explorer window
- Context sensitive auto-completion using PowerShell, PowerTab and GIT
- Displaying GIT Branch on your PowerShell prompt
XBox Live
Songs I like
Categories
- adobe (4)
- amarok (1)
- C# (2)
- chat application (1)
- crud (2)
- cygwin (1)
- explorer (1)
- expression blend (1)
- flex (4)
- FOSS (2)
- free (1)
- GIT (3)
- ID3 (1)
- java (1)
- microsoft (3)
- mxml (2)
- nokia (1)
- open source (5)
- perl (1)
- powerpoint (2)
- powershell (3)
- rails (3)
- right click (1)
- ruby (9)
- ruby on rails (3)
- security (3)
- silverlight (4)
- smart playlist (1)
- socket (1)
- software (7)
- ssh (1)
- sudo (1)
- tabs (1)
- tomcat (1)
- user interface (6)
- vista (9)
- vista, security (2)
- visual studio 2008 (1)
- win32ole (1)
- windows (13)
- windows media player (1)
- wpf (1)
- xaml (4)
- XP (3)
