Monday, November 3, 2008

Timezone changes in Linux

I moved across timezones recently, and booted up my Gentoo machine. I modified /etc/conf.d/clock, but the "date" command kept giving back the time in my old timezone. Turns out you also have to change /etc/localtime .

As seen in the Gentoo manual

Monday, September 8, 2008

Lowering process priority on the command line

If there's a process that you want to start from the command line, or through a shortcut, but you want it to automatically have a higher or lower priority, use this syntax:
C:\WINDOWS\system32\cmd.exe /c start "DC++" /low "C:\path\to\program.exe"

This will ensure that the program always gives up CPU time to other processes.

Friday, August 8, 2008

Remote Desktop to a Virtual Machine

A little while ago I tried to Remote Desktop to a Windows XP Virtual Machine (hosted on a Gentoo Linux system) from work, and it wouldn't connect. I knew I could Remote Desktop from my WinXP workstation, so I found out that I could still get in by Remote Desktopping to my workstation, then using Remote Desktop on the workstation to get to the VM.

That's a terrible work-around though, so I looked around for a proper solution. One of my friends told me a possible fix, I tried it, and it worked. You have to write "1" to /proc/sys/net/ipv4/ip_forward. This makes it so that the host OS will accept traffic not intended for itself, and forward it to the VMware net interfaces.

Here is the /etc/init.d script I used to make this happen automatically:
#!/sbin/runscript
start() {
ebegin "Starting ${SVCNAME}"
echo 1 >> /proc/sys/net/ipv4/ip_forward
eend $?
}

stop() {
ebegin "Stopping ${SVCNAME}"
eend $?
}

Haven't had an issue since.

Tuesday, July 22, 2008

Making directories

Twice in the past month I've had great frustration because of tools that would create a file given a non-existent filename, but would not create the directory structure necessary to hold the file, if it didn't exist.

First off, the Ogg Vorbis encoder provided by RareWares is capable of auto-creating directories if they're specified in the output path. However, the Lame encoder, also provided by RareWares, does not. The directory needs to be created manually first if it doesn't exist, before a file can be written there.

I had the same issue with Perl's open() procedure. It will create a file that doesn't exist, but the directory has to be there already.

I know it's good practice to check for these things, but it's still annoying, chasing down an error like that.

Wednesday, July 9, 2008

MarqueeAnimationSpeed

I was having issues with a progress bar that was set to Marquee style. It was moving at a pretty good rate, and setting the MarqueeAnimationSpeed value seemed to have no effect. Turns out that you need to specify the speed before you set the ProgressBar to Marquee. In my case, the working code looks like this:


encodeProgress->MarqueeAnimationSpeed = 35;
encodeProgress->Style = ProgressBarStyle::Marquee;


I imagine that's the exact problem that this person had. It's a shame Microsoft didn't figure out what the person had done.

Friday, June 13, 2008

Visual Studio - Icons

There are a few things involved in adding icons to a Visual Studio project. Where applicable, this guide will reference GIMPshop, but the procedure should be very similar in Photoshop or GIMP (I don't know for sure, as I haven't recently used either one).

First, make your icon in a larger resolution. 255x255 works well, since that's the largest size that the end result can be (Vista allows 255x255/256x256 icons if you have "large icons" enabled). After you have it as you want it, save it as a PNG, then scale it down to 3 different resolutions: 48x48, 32x32, and 16x16. All of these should be scaled down from the original 255x255, as that will provide the best-looking icons. After scaling, some manual pixel manipulation might be needed in order to produce the best-looking results, depending on the nature of the icon.

After you have all 4 image files, open up the 255x255 file, then "Open as Layer" the same file twice more. Then "Open as Layer" each of the other three files three times each. Save the whole thing as an Microsoft Windows Icon file (.ico). A window will come up with each of the layers in it, and next to each layer is a dropdown box. The box lets you select the color bitrate for each layer. For each image size, you want one layer to be 32-bit, one layer to be 8-bit, and one layer to be 4-bit. Reducing the bitrate may require additional touching-up as well.

You now have an icon file that can be imported into Visual Studio. There are two places where it should be imported into your project. The first is in the main window. In the window's Icon field, select the file you just made. Then do the same in the application's properties page (though VS may like it more if you import the icon as a Resource, then add it that way).

With this, Windows should know when to use the right filesize and bitrate for any given situation. These 12 images are all that's recommended by Microsoft for Vista compatibility, but you can put in more if you want to be prepared for situations where Windows would otherwise scale the icons for you.

Tuesday, June 3, 2008

ClickOnce - Publisher Name

Something I'd forgotten: the item that determines the placement of a ClickOnce application within the Start menu is in Options->Publisher Name. I'm not sure how to publish to subfolders with ClickOnce yet though.

Thursday, May 29, 2008

Renaming "Form1"

Visual Studio should really allow you to change the name of the startup form on creation of a new project, or at least have a more descriptive name, such as (ProjectName)Main. However, they don't do this, and you're stuck with the entirely bland and nondescript Form1.

There is a way around this though: it's still much easier to do this right after you create the project rather than a long time down the road, but here it is:

-Rename the filename of the main form (Form1.cs, Form1.h, etc).
-Press Ctrl+H (brings up Quick Replace menu)
-Change "Look in" to "Entire Solution" (not just that file)
-Find "Form1", replace with the new name you've chosen.

Tuesday, May 27, 2008

Recurse directories with C#

I'm working on a C# program that recurses through directories, adding all the files to a list (I felt like trying out C#, and this was a good place to start). I found this VB.NET program doing something very similar, and adapted it to C#.

private void recurseDirs(String rootdir) {
DirectoryInfo dirinfo = new DirectoryInfo(rootdir);
foreach(FileInfo fi in dirinfo.GetFiles()){
FileList.Items.Add(fi.FullName);
}
foreach(DirectoryInfo di in dirinfo.GetDirectories()){
recurseDirs(di.FullName);
}
}

Friday, May 16, 2008

wget, and HTTP passwords

So, it turns out that wget has support for passworded HTTP files. It doesn't prompt by default like most browsers do; it just gets the 401 error code. However, using the options "--user=username" or "--http-user=username" and "--password=pass" or "--http-password=pass", you can get files hidden behind these user:pass mechanisms.

Wednesday, April 30, 2008

F-keys as control characters

It's somewhat easily found online that control characters map onto a keyboard easily. Take the numeric value of the control character, add 64, and you get a letter. Press Ctrl and this letter, and you get the control character.

However, one thing I couldn't fine anywhere online was how the F-keys mapped to ASCII. I needed a way to send them over a serial connection, and couldn't find a way.

Turns out that F1 is sent in three bytes; in decimal they are 27, 79, 80. For the other F-keys, the last byte is incremented, up to F4 (27, 79, 83). HyperTerm doesn't seem to send anything if you press F5 and beyond.

Tuesday, April 29, 2008

Dell notebook fans

I was working with a Dell laptop (Inspiron 1150, to be specific) last week whose fan had stopped working. The computer was going into auto-shutdown in a matter of minutes, even with an Antec cooling pad (a very nice pad, by the way), because it happened to be a particularly hot day. I looked up the price of a new heatsink/fan assembly, and found it to be somewhat reasonable ($20-30 on ebay), and was getting ready to order a new one, and attempt to install it myself. I've never fully taken apart a notebook before, only minor disassembly for the purposes of removing dust or doing minor upgrades, like adding RAM.

Fortunately, it wasn't necessary to order the new fan, because I stumbled across a third-party Dell fan control utility, which allowed me to adjust the fan speed manually. I'm aware of SpeedFan, but it didn't seem to recognize the fan. The fan wouldn't run at any speed less than full anymore, so I had to use the utility to set the fan speed to max on startup, and just leave it at that. I guess the fan isn't dead, but maybe the internal fan controller is malfunctioning?

XP SP3

Microsoft has released Windows XP Service Pack 3 today. As a side effect of the increased security features though, some people have seen a couple of instances of trouble related to the increased security features. For example, downloading files over a LAN has been made more secure, which has caused at least a few people issues. Fortunately, there is a workaround for those who need this functionality.

Update: Scratch that...

In before title change

Hey there! I'm not really one for blogging in a huge way, but I comment on some blogs on a regular basis, so I figure I might as well make one, and then occasionally post stuff that piques my interest. I imagine most of it will be related to computers, networking, and programming, but I may go for other topics if I feel like it. I may change the title, cause I'm not sure I like it, but I hope something I post here is useful to someone else. If not, then at least I have a good archive for stuff that's interesting to me, like stupid C tricks.