windows

Windows batch: automating start of day

I read someone on twitter stating that their resolution was to automate repetitive tasks. This is not my resolution, but I thought it was an excellent idea.

One task that I do every time I turn on the computer is opening 4 essential programs. This takes a few minutes. It is boring. I need to open IE, Fireforx, pidgin, and skype. I have task buttons for IE and Fireforx, and Pigdin can be found on the top of my start menu. Skype will rise and fall depending on how recent the last update was. The last two are the reason why the process can delay a bit.

So I wrote this simple batch file to open them all. The script switches to the directory of the program and starts it in the background. In bash we would use & to push the process to the background; in windows it is using the command "start". Then I created a shortcut that I dropped on the desktop. And I was finished.

Now the whole process takes around 30 seconds with a single double click.

set originalPath= %CD%
 
cd "C:\Program Files\Mozilla Firefox"
start firefox.exe
 
cd "C:\Program Files\Internet Explorer\"
start iexplore.exe
 
cd"C:\Program Files\Pidgin"
start pidgin.exe
 
cd "C:\Program Files\Skype\Phone"
start skype.exe
 
cd %originalPath%
echo End of Script

Ruby: Automating service start up in windows

In my windows 7 machine, I have a lot of services that I keep turned off. I turn them on only when I actually needed them. This keeps my computer working better than if I had all of the services running at the same time.

So every time that I need to turn them on, I have to manually go to the Services control and start each service. Pursuing the goal of attempting to automate as many repetitive tasks as possible, I wrote this small ruby script that, when one runs it as administrator (windowsese for sudo), it will start both of them up with one action and less time.

services = ['Apache2.2', 'MySQL']
 
services.each do |service|
 command = "net start #{service}"
 system command
end

Cygwin and Ruby Windows

cygwin logo

I installed ruby on windows using the one-click installer. Later on, I installed cygwin as my git shell (in my experience, cygwin is the best git shell there is for windows). As most people who work with cygwin know, you can't run gem or rspec from cygwin without further configurations. It returns an error if you attempt to do that. I had to run rspec using the cmd.exe windows shell, and then commit the work using git via the cygwin shell. Not a terrible burden, but cumbersome.

I knew that I could download a cygwin copy of ruby, but I didn't want to do it because I already had my ruby gems the way I liked them. And I also noticed that running ruby -v in cygwin would give me the version of ruby found in C:\ruby192. After examining the error message that I got when I tried to run gem or rspec in cygwin, I saw that I could run gem.bat or rspect.bat successfully in the cygwin shell. So there had to be an easy way to use windows ruby and cygwin.

Well, there is.

After looking around on the net, I found this answer by Robert Wahler in stack overflow.

You go to .bashrc in your cygwin installation (found in C:\cygwin\home\ in my computer ), and at the bottom you add the following aliases:

alias gem='gem.bat'
alias rake='rake.bat'
alias erb='erb.bat'
alias irb='irb.bat'
alias rdoc='rdoc.bat'
alias ri='ri.bat'
alias rspec='rspec.bat'
alias cucumber='cucumber.bat'
alias bundle='bundle.bat'

Start the cygwin shell again, and now you will be able to use gem and rspec without having to use the .bat extensions.

http://stackoverflow.com/questions/3831131/rubygems-cygwin-posix-path-no...

Ruby, Windows: make is not recognized as an internal or external command

I was trying to install hpricot on my windows computer. I had done this before, but this time I was getting the following error:

" make is not recognized as an internal or external command"

The solution for this problem was to use the following command:

gem install (gemname) --platform=mswin32

I found that in stackoverflow, in an answer given by freek. Thanks!
http://stackoverflow.com/questions/1718500/installing-hpricot-on-ruby-1-...

Drupal: Detailed instructions for installing simple test on Drupal 6 running on Windows

Photobucket

A while ago I said that I may come back and enter detail instructions on how to install simple test on drupal 6 on Windows. I forgot about it, and, of course, I need that information now. So here it is, in its detailed glory, how to do this.

1. Download simple test from this link http://drupal.org/project/simpletest

2. Make sure that you have curl installed. Check whether curl has been installed by looking at your phpinfo() page, or running on the command line php -i . If you don't have it installed, install it. On windows, that means going to your php.ini, and uncommenting the line where it says php_curl.dll and potentially moving php_curl.dll to Windows/system32 More information on this link http://www.php.net/manual/en/curl.installation.php read the 28-Dec-2009 07:17 comment by wixelbomb for more details on it.

3. Run the patch on drupal 6 core. Oh, boy, was this fun 2 months ago.
First, information on applying the patch is given here http://drupal.org/patch/apply If you are using windows, that means that the utility that you need must be run in cygwin http://www.cygwin.com/ or you need http://unxutils.sourceforge.net/ . That is actually not that bad. More information specific to windows on http://drupal.org/node/60179

What ended up being hard to figure out where you should run the patch. The answer to this, for simpletest, is your root drupal directory. Since I don't like to type too much, I copied and pasted D6-core-simpletest.patch to root, and ran the following command in cygwin

patch -p0 < D6-core-simpletest.patch

That should be it. Then you can have fun testing.

SQL*Plus: How to change directory from while using Command Line SQL*Plus

The Answer:

To see current working directory within Sql*Plus command line:
host echo %CD%

To change directories:
host cd c:\go\toyour\directory

Long story:
the command 'host' in sql*plus let's you perform calls to the shell/command line of the operating system that you are using. In this case I am using windows, so instead of using the handy pwd, I had to use the clunky echo %CD%. Style aside, it works.

Thanks, shoover at stackoverflow for the quick answer to this question :)

http://stackoverflow.com/questions/1840816/sql-plus-how-to-change-direct...

Ruby and MSSQL on Windows: link to best page ever

This was the only code that I found where it made it easy to execute a query to a MS SQL Server db. If you are running it on windows, the libary, win32ole, comes with the installation. It is a small class that handles the connection and execution of the db.

I normally copy interesting code here and give the link, but the post is so short and to the point that I will just thank David Mullet, for this great piece of code. It made my day :)

http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html

I changed my mind. Here is the text of the post:

Ruby, ADO, and SQLServer

Ruby and ActiveX Data Objects (ADO) make working with Microsoft SQL Server databases simple. Here's a simple example of a class that manages the SQL Server database connection and queries:

require 'win32ole'

class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields

def initialize
@connection = nil
@data = nil
end

def open
# Open ADO connection to the SQL Server database
connection_string = "Provider=SQLOLEDB.1;"
connection_string << "Persist Security Info=False;"
connection_string << "User ID=USER_ID;"
connection_string << "password=PASSWORD;"
connection_string << "Initial Catalog=DATABASE;"
connection_string << "Data Source=IP_ADDRESS;"
connection_string << "Network Library=dbmssocn"
@connection = WIN32OLE.new('ADODB.Connection')
@connection.Open(connection_string)
end

def query(sql)
# Create an instance of an ADO Recordset
recordset = WIN32OLE.new('ADODB.Recordset')
# Open the recordset, using an SQL statement and the
# existing ADO connection
recordset.Open(sql, @connection)
# Create and populate an array of field names
@fields = []
recordset.Fields.each do |field|
@fields << field.Name
end
begin
# Move to the first record/row, if any exist
recordset.MoveFirst
# Grab all records
@data = recordset.GetRows
rescue
@data = []
end
recordset.Close
# An ADO Recordset's GetRows method returns an array
# of columns, so we'll use the transpose method to
# convert it to an array of rows
@data = @data.transpose
end

def close
@connection.Close
end
end

You can then use this class as follows:

db = SqlServer.new
db.open
db.query("SELECT PLAYER FROM PLAYERS WHERE TEAM = 'REDS';")
field_names = db.fields
players = db.data
db.close

The above code is, of course, incomplete and can certainly be improved and extended (error handling, etc.). But, hopefully, it provides you with a solid foundation on which to build.

UPDATE: You might like to know that you can automate many of your SQL Server administrative tasks by leveraging Distributed Management Objects (SQL-DMO). I've explained this in a later article here.

Thanks for stopping by!

Cygwin bash scripting won't work: beware the CrLF, my son!

So my nice little bash script wasn't woking on cygwin. What could be wrong? I was getting a weird error saying that my file was not ending correctly.

What was the problem?

Answer: working on Windows.

No, it is not what it sounds! No OS zealotry here! The problem was that my beloved Vim adapts to its environs very well, so it was adding a CrLF at the end of my script file. Cygwin couldn't deal with that, ergo the error. http://stackoverflow.com/questions/630650/errors-on-beginner-bash-script

The solution on vim is easy:
:set fileformat=unix
:w

I found the solution here:

Syndicate content