I was recently re-organizing my music collection and.. Well, I suppose “re-organizing” implies a level of initial organization that my collection has never enjoyed. So..
I was recently organizing my music collection and noticed that it involved a number of repetitive tasks pertaining to folder management. Specifically, I wanted to
- get rid of folders that only had one file in them
- get rid of all empty folders
- Do some mp3 tag reading and make some decisions based on that
The goal is not really the point, but the general task I wanted to completed was enumerate every folder in some base folder, test a condition (e.g. Is directory Empty), and based on the result of the condition execute some action (e.g. delete the directory).
Typically I’d write a script for this (vbscript or maybe batch) but I was recently doing some directory enumeration in C#, so I figured I’d reuse that code.
The result – a shell application to perform an arbitrary task given an arbitrary condition – ccDirectoryManipulator.
Sadly, it was just brought to my attention that the site has been filtering out some legitimate comments as Spam. Very sorry about that, I have disabled spam filtering and will keep it just captcha for now.
In light of the filtered posts, I’ll be posting an update to ccQuickMint very soon to accomodate the new file format.. Hopefully, just in time to do the year-end books.
Recently I was messing around with some webcam image acquisition and thought I’d share some code that I wrote for this purpose. The code below implements a class that can capture a single image from a webcam and return it as an array of bytes or simply store it in a file – no dialogs, no frills.
First, there are several ways to go about webcam image acquisition with C# in Windows. There is Windows Image Acquisition library (WIA), Direct X interfaces, and third-party libraries like EasyWebCam Library
Finally, there is the option of using interop to call into avicap32.dll. This is the method I went with, because it is lightweight and works with more cameras than WIA (in my trials anyway).
I recently discovered a little bug in Kwapture, a little screen cap app I wrote. The issue was that when the user selected a small area, it would automatically get resized to a larger size.
Yes. Another WTF file entry. Well.. sort of..
The way Kwapture works, is that after you select an area to capture, it creates another dialog over that area that uses the underlying image as a background and allows the user to draw/write on top of that. The dialog is dynamically sized using the size of the rectangle selected by user.
The dialog that is created is essentially blank:
AutoScaleMode = None
ControlBox = Flase
ShowIcon = False
ShowInTaskBar = False
However, I realized that when the user selection was below a certain size, it would always get resized to the same larger size… Approximately like this – the smallest size you can shrink Notepad into:
Well.. long story short, changing the MinimumSize attribute from 0,0 to 1,1 solves the problem!.
I am guessing that if minimum size is 0,0 there is some pesky if statement that sets the minimum size to accomodate the control box and the icon and does NOT consired the custom value of these properties. But.. that’s just a guess. None the less, WTF.
Hope this helps,
I originally wrote this light-weight application to get more precise measurements of how my time gets allocated on software projects. However, it evolved as a general consulting tool.
ccProjectTracker allows you to quickly start timing a task when you are in front of your computer (e.g. timing phone calls, email responses, etc). If you are in consulting that involves computer work, this is also handy to keep track how long each part of your project takes. Once the project is complete, ccProjectTracker can export project tasks and their information (start time and end time, duration) to Excel for billing.
- Track multiple projects
- Track multiple tasks within a project
- No database required (project info automatically saved to disk)
- Allows export of tasks to Excel (via CSV file)
- Allows configuration of rounding interval (i.e. increments task duration in billable [e.g. 15 minute] increments)
- Runs in the system tray
- Light-weight (<50 KB)
There comes a time in every person’s life when they have to automate a download from an FTP server. Man, I hope that is not true.. But that time came for me recently, so I thought I’d share the script snippet to accomplish this.
Basically, I needed to set up a scheduled task that would log into an FTP server once a day and download a file. That file would subsequently be consumed by another application, but that’s not the point.
Windows comes equipped with a command-line FTP client which has option to receive a text file with instructions. Thus, the batch script for the scheduled task does the following:
- Create a text file with commands for the FTP sessions
- Calls FTP with the command file as a parameter (performs commands)
- Deletes the file with the commands
A few code snippets below are a “quick’n’dirty”. Please use with caution at your own risk.
Updating UI from Another Thread
Since not so long ago, your C# code will throw an exception if you attempt to update WinForm UI from a worker thread. The exception can take a couple of different forms, but typically looks something like:
Cross-thread operation not valid: Control ” accessed from a thread other than the thread it was created on
So in a situation where you have, say, a button that starts a thread that performs a computation AND you need to update a UI element with each iteration of the computation, you will now have to jump through some hoops.
I have written about a subset of this issue before, but it seems more problems keep coming out of the woodwork. One of the drawbacks of the otherwise king of awesome vSphere architecture is that it uses an MSSql database for stupid stuff. But that’s not the real issue. The real issue is that it does not clean up after itself and eventually the database ‘gets full’ due to logging and other nonsense that has nothing to do with the functionality of a Virtual Center deployment.
In my last article I wrote about the “The transaction log for database ‘VIM_VCDB’ is full.” error. My solution, which sadly is still the only one I am aware of was to have a scheduled task that executes a SQL script and shrinks the transaction log. However, some new yet similar errors have emerged that required me to expand my script a little, so I though I would share it.
The following are just some of the messages you may be seeing:
- VMWare VirtualCenter Server starts and then immediately exist
- Event Log contains:
- Could not allocate space for object ‘dbo.VPX_HOST_VM_CONFIG_OPTION’.’PK_VPX_HOST_VM_CONFIG_OPTION’ in database ‘VIM_VCDB’ because the ‘PRIMARY’ filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
- An unrecoverable problem has occurred, stopping the VMware VirtualCenter service. Error: Error[VdbODBCError] (-1) “ODBC error: (42000) – [Microsoft][ SQL Native Client][ SQL Server]Could not allocate space for object ‘dbo.VPX_HOST_VM_CONFIG_OPTION’.’PK_VPX_HOST_VM_CONFIG_OPTION’ in database ‘VIM_VCDB’ because the ‘PRIMARY’ filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.” is returned when executing SQL statement “INSERT INTO VPX_HOST_VM_CONFIG_OPTION WITH (ROWLOCK) (HOST_ID, CONFIG_OPTION_VER, DATA, ARRAY_INDEX, CONFIG_OPTION_DESC, CREATE_SUPPORTED_FLG, DEFAULT_CONFIG_OPTION_FLG) VALUES (?, ?, ?, ?, ?, ?, ?)”
- CREATE DATABASE or ALTER DATABASE failed because the resulting cumulative database size would exceed your licensed limit of 4096 MB per database.
This is another installment in the WCF vs. WTF article series. I mentioned before that I am quite a fan of WCF but having said that, feel that there are a few areas for improvement like sending method comments with the service contract discovery and more streamlined debugging, to name a couple.
The truth is that WCF actually provides some decent tools to debug service issues. However, I feel that the tools are a bit cumbersome to use and the bigger issue that the exception that bubbles up to the top is not necessarily informative of what actually caused the issue and requires digging deeper.
So.. Here is a pretty generic client error:
The underlying connection was closed: An unexpected error occurred on a receive. – at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
An error occurred while receiving the HTTP response to http://localhost:8731/Design_Time_Addresses/SomeService/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
I needed to conduct some remote management on our VMWare ESXi hosts recently, and found out the hard way that the SSH functionality is disabled by default. Not sure if that’s an appropriate default for a virtualization platform, but whatever..
There are a couple of ways to enable SSH access on the hosts. One involves going over to the machine and interacting with the console.. Thumbs down for me, since the hosts are physically about 2000 miles away. But after a little digging, I found an easy way to enable SSH support via vSphere Client.
Just select the host in question, and go to the ‘Configuration Tab’. Under ‘Software’ box (not sure about how awesome I feel about the vSphere Client UI,..), select ‘Security Profile’. Look very very hard to find a ‘Proeprties…’ link in the top right-hand corner and click that – depending on your resolution/window size, you may have to actually scroll to the right to see it!
Today I celebrated my first father’s day (as a father). It was awesome – enjoyed some delicious labrusco in the morning, worked on my back yard project, had a great time BBQing at my parents’ place. But somehow, some way, the forces tha be made it more memorable..
You see, less than a month ago I aquired an Eee Pad transformer, which is/was awesome. I love this device – spectacular functionality and hardware specifications (for the time), excellent price point, just all around a great casual computing device. However, apparently it was not designed to ride in the bottom of a baby stroller. Shit!.. I left it in the little pocket under the seat, folded the stroller into the trunk, and when I got home from my parents’ and pulled the stroller out of the trunk… It looked like a crumpled piece of paper..
I have been a casual “portfolio manager” for a number of years now. What this really means, is that I have some money that I personally actively, yet casually, manage and by doing so also reduce my life expectancy by pegging my blood pressure to market volatility. After getting an MBA a few years back, my knowledge base pertaining to securities investments reached “enough to be dangerous” level. However, one positive thing that came out of my education was a better grasp of portfolio metrics and also a realization that portfolio management tools provided by discount brokers fall far short of what would be required to make educated decisions on portfolio risk, asset allocation and more importantly information on how these metrics change over time. Thus, I set out to write some number crunching algorithms of my own in order to better understand how my money is actually invested.
This is what I hope to be a first in a series of articles (depending on the feedback I receive) on performing financial analysis in C#. I plan to cover a few things, namely:
- Calculating basic portfolio statistics
- Mining stock data from various online resources
- Calculating sector sensitivity
- Monitoring changes in portfolio sensitivity and risk profiles
- and maybe down the road, I’ll talk about some goofy stuff I’m doing with neural network analysis pertaining to re-allocation decisions
Please understand, that all of this is provided without warranty of any kind and is not meant to be an investment advice. For advice on investment decisions you should most definitely seek help from a licensed professional.
Ok, well this has nothing to do with anything, but I tend to find scam emails slightly humorous. So here goes a recent contender – How tried is this pitch already?! But yet someone somewhere must be falling for it, because they keep coming.. Enjoy:
My name is Mr. Song Li. I work with the Hang Seng
Bank.There is a sum of
$19,500,000.00 in my bank Hang Seng Bank”,Hong Kong.
There were no beneficiaries stated concerning these funds which means no one
would ever come to claim it.
That is why I ask that we work together.I do solicit for
your assistance in effecting this transaction.I intend to give 30% of the total
funds as compensation for your assistance. I will notify you on the full
transaction on receipt of your response if interested, and I shall send you the
details and necessary procedures with which to make thetransfer.
Should you be interested?
(2)private phone number:
(3)current residential address:
Mr. Song Li
There are tons of articles out there on how to bind a list of object to a DataGridView. To save you the time, I’ll just say that if involves this:
myGridView.DataSource = myList;
That’s quite lovely, but sometimes that’s not what we’re after.
Sometimes, I just want to bind a single object’s properties to a DataGridView for the purpose of just displaying the object and the values of it’s member variables. Ok Ok, so this is not exactly a “binding” since it’s not a two-way relationship, but first, binding something or someone in real life rarely is, and second, coming from a CS/EE background I am fairly used to relationships that are not necessarily two-way 🙂 .
So, say you have an object like this: