programming
TIM: Time Is Money! Standalone meeting calculator in HTML/Javascript
This is my take on TIM calculator, you can download, modify and run it in any browser (I’ve tested with IE8, Chrome, FF). View, download or use it online.
Modify the currency to your liking. Oh, and of course, best viewed with Chrome.
explorer.exe hard faults excessively and opens way too many file handles — looks like tortoise svn is slowing me down, what a surprise.
UPDATE: It turned out that the reason is not TortoiseSVN, my apologies to the development team.
Recently, more and more often, explorer.exe started to cause excessive hard faults like 13k/min. When I tried to look at what the fuck explorer.exe is doing, I noticed it was opening hundreds of file handles in my Code directory, which has several sub directories with hundreds of thousands of small files (source codes). I saw this a few times but this time it struck me that it could be because of Tortoise SVN. When you open a folder in Windows Explorer, soon you start to see SVN folders are marked with an icon, thanks to Tortoise SVN. To achieve that it must be traversing through subfolders and looking for the infamous hidden .svn folder.
With that in mind, I started to examine opened file handles more closely. Then I realized that most of them are .svn folders. So, I uninstalled Tortoise SVN immediately it asked me for a reboot, I said “no”. I manually restarted explorer.exe process to get rid of the in-memory Tortoise SVN. Now my hard faults looks like stopped.
And it is indeed quite ironic that a software named Tortoise slowed my computer down. So, we found something else SVN is bad at :)
How to develop, install, debug Windows Services
- Create a Windows Service project.
- Read documentation about the methods (OnStart and OnStop) you had to implement and implement them
- Try to debug.
- You’ll get:
Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.
- InstallUtil.exe is in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe for me. There was another InstallUtil before that, in the PATH. Hence I needed the absolute path.
- When you try to install your service, if you look close enough you’ll see:
No public installers with the RunInstallerAttribute.Yes attribute could be found in the c:\Users\Engin\Code\RunawayKiller\RunawayKiller\bin\Debug\RunawayKiller.exe assembly.
- It turns out you need to have a special public class in your assembly to tell InstallUtil.exe what to do. Here’s my class:
using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.ServiceProcess; namespace RunawayKiller { [RunInstaller(true)] public class ProjectInstaller : System.Configuration.Install.Installer { private ServiceInstaller serviceInstaller; private ServiceProcessInstaller processInstaller; public ProjectInstaller() { processInstaller = new ServiceProcessInstaller(); serviceInstaller = new ServiceInstaller(); processInstaller.Account = ServiceAccount.LocalSystem; serviceInstaller.StartType = ServiceStartMode.Manual; serviceInstaller.ServiceName = "Runaway Process Killer"; Installers.Add(serviceInstaller); Installers.Add(processInstaller); } } } - Now, when you InstallUtil.exe your assembly, you’ll see your service in the Windows Services list. You can run it.
- You need to do this InstallUtil installation just once. When you update your assembly (i.e. with new code) just restart the service and your new code will run.
- Debugging is still not straightforward. Documentations tell that you need to go “Debug > Attach to process” and attach to the running service. In my case, it was greyed out.
- A work around is to call System.Diagnostics.Debugger.Launch(); to trigger Windows to launch a debugger to the debug the process. I put this on OnStart
- When you run the service, Windows will ask you to chose a debugger. You instance won’t be listed there unless you run Visual Studio with administrator privileges. I recommend you to do so. Run Visual Studio with administrator privileges and open your Windows Service project. And when you start your service, chose that instance of Visual Studio to debug. It will tell you There is no source code available for the current location. Don’t mind this warning and click OK.
- Now you can set break points in your source code and click Continue to run your service.
Disclaimer: These are my notes from a 45 minute trip during rush hour and not necessarily the best practices whatsoever.
gnuplot performance on windows
gnuplot is an unbelievably good tool, if you don’t know it yet, check it out. Though the gnuplot Windows package has performance problems. No matter how much I tweaked the parameters and tried different rendering engines (terminal in gnuplot jargon), I couldn’t fix it. It was taking more than 5 seconds to render 350k data points.
Cygwin is a part of my toolchain. Today I figured I might give gnuplot with Cygwin/X11 a shot. Cygwin also has a gnuplot package which is built for Cygwin environment. Cygwin also has a X11 package, so that you can run a X11 server on your Windows box. Actually there are several other X11 server implementations for Windows out there, even commercial ones. Anyway, I’ve tried to plot my graphs using Cygwin gnuplot and X11. And voila! It was about 5 times faster.
So, having gnuplot performance problems on Windows ? If you don’t mind installing Cygwin (which is simply a double click and next, next, next) you can enjoy a faster gnuplot experience.
Free virtualization on headless hosts; vmware-server2 and virtualbox (vboxheadless)
Virtualization is cool. It gives you the ability to:
- Deploy nodes into your cluster in minutes
- Get the most out of your hardware, even if your software is not very efficient. i.e. it is proven that multiple instances of MS IIS running on a host in separate VMs are more efficient than a single MS IIS instance on the host. Which implies that MS IIS is not engineered to utulize hardware very well.
vmware-server 2
In short:
- Installation: very easy.
- Management: Web access did not work. VMWare Infrastructure Client did not work.
- Stability: Crashes on guest OS update.
First of all, I want to say that I’ve used this a couple of years ago and I was very pleased with it. Now I tried to install it on CentOS 5.5 host to install a Windows 2003 guest OS. Installation was a breeze but managing the virtual machines turned into a nightmare. I couldn’t reliably access to the web interface no matter what I tried. According to logs there was an error in SSL handshaking, tried to solve the issue by trying a few workarounds presented in forums, with no luck.
Then, I recalled that there was a native desktop application called VMWare Infrastructure Client which I used previously. It was previously located on https://host:8333/clients/ but now it is not there for some reason. It is not even in the docroot directory on the host. It simply is not there.
Then, with the help of google I found the executable and installed it. I connected to the host but the console was always blank (white). Then I googled a bit more to find out that VIC has some problems if it co-exists with the new VIC (VMWare sphere client). Then I removed the new client and installed the v2.5 again. This time it worked. I installed the Windows 2003 server. Mind that I occasionally lost connection to the console during this process.
After the initial boot, I tried to update the server through Windows Update. One of the child processes of VMWare consistently crashed at this point, rendering whole VMWare unusable. I tried a few times, it always crashed at this point with a core dump and backtrace in the logs.
At this point, I give up giving any more chances to vmware-server 2 on CentOS 5.5.
VirtualBox
Then I started looking around if VirtualBox had support for headless hosts, it turned out it has some basic support — with decent documentation.
First install VirtualBox for your platform. I simply added repo to /etc/yum/repo.d and installed via yum. Then install extension packs. Which basically boils down to this;
[root@tr ~]# wget http://download.virtualbox.org/virtualbox/4.0.0/Oracle_VM_VirtualBox_Extension_Pack-4.0.0-69151.vbox-extpack [root@tr ~]# VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.0.0-69151.vbox-extpack
See Installing Guest OS on a headless VirtalBox host.
Notes:
- In the example, it is using NAT as networking, you probably want bridged;
- At first, I tried –cpus 4, but it gave me “Error: failed to start machine. Error message: Unknown error creating VM (VERR_VMX_MSR_LOCKED_OR_DISABLED)”. I simply fell back to –cpus 1, and it is working fine.
I’ve used:
[root@tr ~]# VBoxManage modifyvm "Win2003E" --memory 2048 --acpi on --boot1 dvd --nic1 bridged --cpus 1 --bridgeadapter1 eth0
Then, of course we need Guest Additions. It is a matter of clicking on traditional VirtualBox installation, but this is a headless installation. I just mounted the VBoxGuestAdditions.iso myself.
[root@tr ~]# VBoxManage storageattach "Win2003E" --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso
It automatically starts the setup, just follow the wizard and you’ll be on your way.
At this point, you should have Windows 2003 server up and running with VirtualBox Guest additions. I’d also recommend taking snapshots along the way.[root@tr ~]# VBoxManage snapshot "Win2003E" take "VBox guest additions installed"Nice.
Java Gotcha: Executing code via Timer vs ScheduledExecutorService
A customer called to report that he cannot read values of two of his devices from the server. In fact, he was not able to read any values of any devices, but since he is served with the most up to date cache results for the other devices, he was not aware of that part of the problem. I connected to the server via remote debugging of Java, which kicks ass by the way, only to find out that the Timer is not executing my code which update the values of the devices currently being watched. It was weird, because the server has been running for weeks and it just stop functioning. It turned out that if an exception occurs in the code Timer is calling, Timer stops executing the code all together in the future. Which, in practice, means that one of your threads is not functioning anymore. Then I learned about ScheduledExecutorService, it is specifically designed to run code. It handles exceptions much more gracefully. So, long story short, use ScheduledExecutorService instead of Timer when you want to execute code. The good thing is, it is quite easy to port your code to use ScheduledExecutorService.
Recover Missing Android Market and YouTube App in Samsung Galaxy S
Why does it happen ?
- Most likely you are in a region where vendor does not add these apps (or operator does not want, who knows)
How to fix it ?
I think the best fix would be to use a stock firmware where these apps are available, this is the cleanest and healthiest approach imho. To do that;
- Get necessary tools “ODIN + PIT” and a firmware (I picked I9000XXJPY) from http://forum.xda-developers.com/showthread.php?t=846913
- Follow the instructions about how to use odin here http://android.modaco.com/content/samsung-galaxy-s-s-modaco-com/311349/flash-now-your-samsung-galaxy-s/
At this point you should have Android Market and Youtube apps working, but market has a region restriction, for instance you might not see Skype in the market. A workaround is to root your device and install MarketAccess. Here’s how.
- Root your device by following the instructions at http://forum.xda-developers.com/showthread.php?t=803682
- Install MarketAccess from http://amip.tools-for.net/wiki/android/marketaccess
Now you can pretend that you are on other operator (i.e. T-Mobile USA) and do stuff.
I might write a review about android platform in another post, if I do it, it will be nasty.
TX FIFO clear problem solved
I’ve mentioned a problem earlier; Expansion Module Architecture Design Experiences of ENDA Devices. It turned out that the API function provided by the MCU vendor SysCtlPeripheralReset() fixes the issue. The slight problem was that, this function blocks for a moment and causes a performance penalty if you use it in a hot spot (such as in my example, which is called my a hardware timer with a high frequency). So I ended issuing the peripheral reset, do business logic, start the peripheral again. It is working like a charm now.
// Issue reset HWREG(SYSCTL_SRCR1) |= SYSCTL_PERIPH_MASK(SYSCTL_PERIPH_SSI0); // Do business logic // Release reset HWREG(SYSCTL_SRCR1) &= ~SYSCTL_PERIPH_MASK(SYSCTL_PERIPH_SSI0)




