Everything in Particular

February 4, 2009

C#: Doing a modulus (mod) operation on a very large number (> Int64.MaxValue)

Filed under: Development, Technology — omatase @ 5:54 pm
/// <summary>
/// calculates a modulus on any number, specifically
/// designed to work around the Int64 limits of the
/// current version of c# which cannot hold a number
/// larger than 9,223,372,036,854,775,807
/// </summary>
/// <param name="iban"></param>
/// <returns></returns>
private static int largeNumberModulus(string numberToModulus, int modulusOperand)
{
string modulusWorkingNumber = numberToModulus;

while (modulusWorkingNumber.Length > 0 && !(modulusWorkingNumber.Length < 18 && Int64.Parse(modulusWorkingNumber) < modulusOperand))
{
// number to work with
Int64 currentNumber = 0;
if (modulusWorkingNumber.Length > 18)
{
currentNumber = Int64.Parse(modulusWorkingNumber.Substring(0, 18));

// remove first 18 characters
modulusWorkingNumber = modulusWorkingNumber.Substring(18);
}
else
{
currentNumber = Int64.Parse(modulusWorkingNumber);

// remove remaining used characters
modulusWorkingNumber = string.Empty;
}

string carryOver = (currentNumber % modulusOperand).ToString();
modulusWorkingNumber = carryOver + modulusWorkingNumber;
}

return int.Parse(modulusWorkingNumber);
}

September 15, 2008

Speed Up Your Computer

Filed under: Technology — omatase @ 4:34 pm

This is a beginners guide to speeding up your computer. This is step one of the guide. For step one we will focus on hard drives. The slowest components in your computer are those with moving parts. This is why it is best to start here. The more RAM, faster CPU craze is something that even consumes some of the experts. The fact is though, that more RAM, faster CPU might not actually be what you need. Indeed spending money on these components might not do anything to speed up your computer at all!

This is the first in a series of articles designed to make it easy for you to know how to speed up your computer (pc or laptop) with the least amount of money or work.

How to know if you need a faster hard drive

Laptop Users:

Most laptops come with slow hard drives to help increase battery life. Although this is the case, putting in a faster hard drive is not likely to cause any battery life problems.

Step 1: What am I working with now?

Most laptops come with 5400 RPM hard drives and most PCs come with 7200 RPM drives. If this is the case for your computer and you are looking to speed up your computer and extend its life, you need to upgrade that to a faster drive. First, though, let’s check your current drive speed. Click: Start, All Programs, Accessories, System Tools, System Information. This should give you a screen that looks like the following:

System Information - Disks

System Information - Disks

Using the above image as your guide, expand Components, Storage then select Disks. On the right-hand pane you will see a description of your disk drive.  Write down the Model (In my case HTS721080G9AT00) and do a search for it on Google. This should bring up results that will give you specification information for your drive and tell you what speed it is. To find the speed look for the numbers 5400 or 7200 and the letters RPM. Drive speed is measured in many ways, the RPM specification shows you how fast the disk spins. Here are the specifications on newegg for my drive:

 

I have highlighted the RPM specification to make it stand out a little more for you.

Once you know your speed you know if an upgrade can help speed up your computer. This is the case if you are using a laptop and you have a 5400 RPM drive (or less) or if you are on a desktop and have a 7200 RPM drive (or less). Here are some links to some good drives that I can recommend to help speed up your computer.

All of these links are from a company called Newegg. I have been a Newegg customer since October of 2003 when they were first getting started. I cannot recommend any online retailer more highly which is why all of my product recommendations link to them.

These links are for some great hard drives focused at performance for your PC or laptop (ordered by most highly recommended) – Updated 09/2008:

Laptop (price range before shipping: $99.99 – $164.99):

Laptop Hard Drive #1

Laptop Hard Drive #2

Laptop Hard Drive #3

PC (price range before shipping :  ($149.99 – $294.99)

PC Hard Drive #1

PC Hard Drive #2

PC Hard Drive #3

June 23, 2008

Bulk / Batch Printing on a Network Attached Epson Dot Matrix Printer

Filed under: Development, Technology — omatase @ 9:49 am

I recently had the “opportunity” to learn first hand how to go attack the topic of batch printing against an Epson Dot Matrix Printer. I’m posting this here to document my woes and difficulties on this very bumpy road.

Defining the Problem

Why should batch printing be any different than single printing? There are a few simple reasons this is different:

  1. Running out of paper
  2. Paper jams
  3. Printer becomes paused

Basically the problem is, if you send 100 print jobs to the printer, you want some way of assuring the jobs actually completed. Imagine if you sent 100 print jobs to the printer and the printer runs out of paper at 50. If your application isn’t set up to do batch printing properly it will send the remaining 50 jobs to the printer even though the printer may have no way of receiving them. Whether it is capable of receiving these jobs is really a matter of the model and how much memory it has to queue up your jobs. The size of the print jobs is also a factor. So your application happily sends the remaining 50 jobs to the printer, how many ultimately print successfully when the paper is loaded? 20? If so what happens to the other 30 print jobs? How does the user even know that they didn’t print or which ones didn’t print?

Finding the Answer

Epson was exactly 0 help on this issue. There was no information online that even gives a hint of a clue of an inkling of where to even start looking. So, I emailed their support department. Here is the email I sent them:

I am writing an application that will print invoices to [a printer with model #LQ-2090]. One requirement of this application is for batch printing. I have a few questions about the support for batch printing with this printer:
1. If it runs out of paper while jobs are being sent to it, what is its behavior? Does it queue requests? What queue limitations (memory limit etc) does it have?
2. If #1 isn’t possible is there a programmatic way to query when the printer is out of paper or otherwise unable to print?
This email was sent originall on 06_05_2008. Since I was actively working on the application I couldn’t wait for their response. The chances it would take too long or that it wouldn’t be helpful were too great. So I did some researching of my own as well. Ultimately the answer came through my own research. I think Epson sent some response about how much memory was available on the printer and then said there was “no way” to ask the printer for a status. So just as I anticipated the response didn’t yield any information that would be helpful, in fact it was wrong about not being able to query the printer for a response. Their email also came several days after I wrapped up the project. I can’t find their response so I can’t say the date exactly but I want to say it took them something like 2 weeks to respond.

The Solution

Ultimately, as I said, I found the answer myself. I was coding along happily one day when one of my colleagues mentioned there was a web server built in to the network card we installed in the printer. Curious, I decided to check it out. It was from that web site that I got my first glimmer of hope. The printer supported SNMP and there were configuration items for setting up SNMP and SNMP traps Sweet! My first instinct was to do it all through traps. Surely the printer would send me a message saying “Please Load Paper” or something like that whenever there was an alert. So I pulled out my Trap Receiver application (iReasoning) and told the printer to send all traps to my desktop. With that all set up I simulated a few scenarios by forcing an out of paper situation, a paused situation and a jam situation. From across the room I could see my trap receiver filling up with traps. Excited I ran over to my computer to see what information the printer was sending me. My elation was premature and short lived. For a few minutes I compared the different traps I had received trying to notice differences. If I was sent the number 12398521 for instance whenever the printer was out of paper, I could just put those values in a config file and be done with it. What I found though over the course of a few minutes was that every trap was the same! What? It didn’t even matter if the trap was sent for a different reason, the data I recieved was exactly the same! Well, the same save for the fact that it was including in the trap an incrementing number. So the first trap sent 0, the second sent 1, the third 2 and so on. Well this is completely useless! If I want to know how many traps I have received I can count them myself! :) . I have a little experience with SNMP traps but if this is a standard thing to do with traps this is a new one for me. Whenever I send a trap I include a human readable message letting someone (or some program) know what is going on. Ultimately I did figure out (I think) what these incrementing numbers were supposed to be telling me. More on that later though. Well, it was apparant that the SNMP traps weren’t going to be of any use. I could treat them like a toggle I guess, but how would I know to have the toggle on or off to begin with? How would I know if I got a message even if the printer was capable of continuing to print? This is not a solution I would except, so I decided to keep looking. The next place I began looking was google. I decided to do a search for something less specific, a search that didn’t include Epson or LQ2090. Doing that got me a hit that ultimately led to the answer. The hit I got was of someone asking how to use SNMP messages to get printer status information. While the article I found was for a different printer and didn’t have any information in it that was, in the end, directly usable getting the hint that SNMP messaging is a possible route I could go was invaluable.

From there it was more and more google searches that led me to this real gem (extreme sarcasm applied here): ftp://ftp.pwg.org/pub/pwg/pmp/mibs/rfc1759.txt. This my friends is rfc 1759. I recommend you look away, look away! Everytime I try to get any useful information from an RFC it always leaves me asking “WHY!?!”. Why on earth would someone write this, and how is it supposed to be useful? After a lot of searching I was finally able to find a guide that explains the RFC. This guide broke down the RFC terminology and explained what it meant, then gave the SNMP OID for each item. This guide, IMO should be the RFC. In any case, guide useful, RFC useLESS! *sigh* ok I feel better now.

As much as I have talked up the guide, it was also ultimately of no help :( . Although it did contain what I was searching for, I couldn’t find what I was looking for as a consequence of just not expecting what I was looking for to be called what it was called.

So how did I find the answer? Good old trial and error / brute force. I opened up my MIB browser app (also by iReasoning) and told it to hit the printer with every SNMP message possible by doing a walk on OID 0. This yielded hundreds of results, with after a little doing I was able to copy into a text file and save it. I did this 3 times: once when the printer had paper and was good to go, once when the printer was in an out-of-paper error state, and once when the printer was paused. I then took those 3 files and did a diff on them using KDiff (a very nice diffing tool). What I found is below (you will want to click to enlarge):

printer diff

The OID that is shown in this diff is the “printmib.prtAlert.prtAlertTable.prtAlertEntry.prtAlertDescription.1″ OID. While this seems like a very reasonable thing to call it I was still unable to find it through my searches either in google or in the above-mentioned guide. I was always searching for things like “printer status” or “out of paper”. In any case, this brute force method did give me all I needed to begin querying the printer for its current state and so I was basically done with my discovery session. I don’t know all of the unique alert descriptions that can be retrieved from this printer on this OID (I couldn’t find a list anywhere from epson even after I knew some items on the list) but here are those I have found: supply the paper, remove the paper, paused. Of course it is not unlikely for this to be different between printer manufacturers and models so you may have to do a bit of trial and error.

One Final Small Problem

One minor final thing I ran into was that the OID would change slightly upon each new alert. The first alert would show up under OID printmib.prtAlert.prtAlertTable.prtAlertEntry.prtAlertDescription.1.0, the second printmib.prtAlert.prtAlertTable.prtAlertEntry.prtAlertDescription.1.1 and so on up the number scale until the printer was power cycled. This gave me another “A-HA!” moment when I suddenly realized what those stupid traps I mentioned before were all about. The aforementioned printer RFC had some information in it indicating the printer could have multiple rows of alerts in a table in its MIB and that there needs to be some method by which one can return things like total number of alerts and current alert index via SNMP. I never figured out how to send an SNMP message to the printer to retrieve the current alert index (although the RFC seems to indicate it is possible), but I now realized the incrementing number in the traps was the alert index. I could then use that number to construct the correct OID for my SNMP message querying the printer for its alert status description! Pretty cool!

Now, For those of you who aren’t receiving or cannot programmatically receive traps from your printer another solution to this problem (and the one I ended up implementing) is to attempt to get the alert description at OID .0. If that fails (or returns an empty value), tell your SNMP client to do a GetNext(). If the GetNext returns a non-empty value that belongs to an OID that begins with “printmib.prtAlert.prtAlertTable.prtAlertEntry.prtAlertDescription.1″, then you are good to go. Here is some sample code that does that for your reference:

[code lang='csharp']

while (manager.LastError == 0 &&  returnedValue.OID.StartsWith(oid))

{

value = returnedValue.Value;
returnedValue = SnmpObject.manager.GetNext();

}[/code]

When this loop completes “value” will have the “next”-most value for the OID we are targeting.

All Done

This marks the end of the material I set out to cover. Hopefully this will be useful to anyone trying to get a batch printing application off the ground. SNMP is universal so as long as your printer is network attached, even with vastly different features, the solution could likely be similar.

Comments and questions welcome, thanks!

July 7, 2007

Why Does No One Remember Apple’s Mistakes? Pt 1

Filed under: Technology — admin @ 5:20 pm

Apple enjoys the most loyal, forgiving (and forgetting) customer base in any industry in the history of the world…

At least that’s the explanation that I have come to. Who was it that said when you have eliminated all other possibilities, that which remains, however unlikely, is the answer? Sherlock Holmes? And when did we start quoting fictional characters giving them credit for coining phrases? Maybe it started with me, here, now?

I for one cannot understand this loyalty. I have to write this article assuming that the latest versions of OSX (within the last 5 years) are absolutely perfect (100% bug free) and have every feature anyone could ever want. This is simply because I haven’t used OSX for about 5 years and it’s only fair to give Apple the benefit of the doubt for products with which I have no experience. So it is entirely possible that loyal fans of Apple may have very good reason to be loyal right now; I really don’t know. What this article is about is how?!?!?! did Apple survive through the end of the 20th century?

My wife who is a PC convert has a degree in Graphical Arts. As everyone knows you can’t learn Graphical Arts in a public school without using a macintosh computer, it’s just not possible. I don’t know what the numbers are, but my impression is that any school that ever teaches this degree does it exclusively with Apple machines. I don’t know why for sure, maybe it’s cheaper for the school that way. I don’t know what kind of deals Apple gives schools on computers. Not really important for the sake of this article.

When I met my wife it was at a time in my life when I had still yet to form an opinion about Apple or Apple-branded hardware and software. It was a simpler time when things made sense. Ignorance was very bliss.

Shortly after I met my wife she got a job working at Smith’s corporate (Smith’s is a grocery store in some mid-western states). Her main function was to use Quark Xpress, Illustrator and Photoshop to create the ads Smith’s would send out in newspapers, etc. There were about half a dozen people in her department. They all used G3 powermacs as their primary machines. I cannot count the number of times the discussion of her day included the number of times her and her coworker’s machines crashed. To this day when asked on an average day how often her work-provided macintosh would crash the number she gives is 2-3. These G3s used the latest and greatest version of Mac OS at the time (OS 9.x, OSX for desktops was released in March of 2001). The time period in which my wife was at this job using these particular computers was 2000 – 2003. This means this was happening when the two prominent Microsoft operating systems on the market were Windows 2000 and Windows XP. Windows ME was hardly prominent as it was released with a bad reputation and was not widely used.

Having your OS crashing 2-3 times per day on average is astronomical! No, this is not an overreaction or sarcasm. It is literally “relating to astronomy” wait… no that’s not it. Oh, here it is “immeasurably numerous, high, or great“. Wow, that’s actually the definition of sarcasm. Ok, this time it’s astronomical and measurable. Trust me 15 years experience working on, fixing, restoring, installing, recovering and just plain old using an operating system says this is a beta-quality software product at best!

I have used some form of Windows OS in a professional work environment since Nov of 1996. I have used Windows 95 (OSR2.1), 98 SE, 2000, XP and Server 2003 as the operating system for my desktop PC over the years. None of these operating systems crashed even once daily on average. In fact I would be compelled to discontinue use of an operating system that crashes that often even if it were a Windows operating system which have had great features that Apple has never had. A few examples of these features are things like compatibility and affordable pricing.

This is the source of my confusion over the loyalty just gushing from the Apple fan base. I have a lot of points to make on this topic and so I am making them in parts.

Stay tuned…

Here’s that quote from above “… when you have eliminated the impossible, whatever remains, however improbable, must be the truth”

wikipedia.org. Sherlock Holmes. Retrieved on 2007-07-03.

June 22, 2007

Why the Playstation Consoles (PS1, PS2, PS3) Suck

Filed under: Entertainment, Technology — admin @ 5:04 pm

Overview

Okay, maybe “suck” is too strong of a word to use but I have a really hard time with Sony’s Playstation consoles. The Playstation console franchise has given us many a good game (i.e. Resident Evil, Devil May Cry, Final Fantasy VII, Metal Gear Solid). Right now I’m playing Final Fantasy XII and I just love it!

What’s So Bad?

But this article is about why it isn’t good and I assure you that list is MUCH longer. First of all is it just me or is the percentage of bad games really high? And much higher than their competition? Certainly Game Cube’s bad game percentage is very low. Sure there are a lot more titles available on the PS2 vs. the Game Cube for instance (or even the XBOX) but what good is that when most of them are so badly done? You might say there are only more bad games for Playstation because there are more games for Playstation. Ok, I’ll buy that, but the problem here isn’t sheer number of bad games so much as the percentage of games that are enjoyable to those that should join the Atari’s ET backfill in the middle of the Mojave.

Ok, aside from the copious amounts of bad software available for the Playstation gaming consoles, what else is so bad about it? Well I have this bad taste in my mouth about the Playstation’s rise to fame. By the time the PS2 came out the Playstation franchise was already well established so for the sake of this discussion I think it is reasonable to focus on how/when/why the PS1 was able to break into the console gaming market. Remember this isn’t a small feat, Atari (the supposed console gaming king of the 70s) didn’t go anywhere (worth mentioning) with the Atari Jaguar and the last reported figures I was privy to on the XBOX indicate that MS lost over $300,000,000 (that’s 300 million dollars) on the XBOX console itself. Now, why do I have such a bad taste in my mouth about Sony’s Playstation having such good positioning in the console gaming market? Simply because I don’t think they deserve it. Why? Because the only reason they are in the position they are in and not just a blip on the console gaming radaar was dumb luck. The ultimate example of right place in the right time. It honestly had very little to do with product quality.

Why Do We Care?

Why is this a problem for us gamers? As video game fans we want the people that are in a position to provide the entertainment to be good at entertaining. The ideal situation would be an underdog system to push through the ranks relying on nothing but sheer entertainment value to boost their base and win market share. What we have with the Playstation phenomenon is the opposite of this. Do we want a good chance of enjoying our gaming experience when we pick up a new game, or a snow ball’s chance in Bowser’s castle?

The Timing Issue

Now, what was this timing issue they took advantage of for PS1 you ask? Simply put, the N64. I am a big Nintendo fan, always have been. That being said I’m willing to admit that the N64 was largely a failure. Here’s why:

  • Firstly, Nintendo spent most of their time, money and all of their media exposure on the N64’s “wonderful” new “ground-breaking” controller. I’ll admit I bought into the whole controller hype pre-N64 but after release we all found out how incredibly cumbersome and over sized it was. I mean it’s a controller that looks like a bat wing replica 2x scale! Not to mention the fact that there were buttons on it that almost no games used! Can anyone name more than 5 games that used the “L” button where the same functionality wasn’t exposed through a different button as well? In fact come to think of it name 5 games that used the left one third of the controller. I much much much prefer the SNES or Game Cube controllers.
  • Secondly, it was a cartridge based system! This was a huge, huge disadvantage for the N64. Hey, I’m all for the speed you get from cartridges but one of the biggest disappointments on the N64 for me was the fact that Squaresoft broke its ties with Nintendo. Final Fantasy VII (the biggest FF hit of the series at the time) was to be released on N64 originally. Why did Square break it’s ties? Mainly the cartridge media type of the N64.

“Late in the 16-bit generation, Square showed an interactive SGI technical demonstration of Final Fantasy for the next generation. However, 1997 saw the release of Final Fantasy VII for the Sony PlayStation and not the Nintendo 64 as many had originally anticipated. This was due to a dispute with Nintendo over its use of faster and more expensive cartridges, as opposed to the slower and cheaper – though much higher capacity – compact discs used on rival systems. Final Fantasy VII would have required a very expensive large capacity cartridge to work on the Nintendo 64. A cartridge holding the game’s three CD-ROM’s worth of data and full-motion video would have been nearly impossible to market at a price that most people could afford.”

wikipedia.org. Final Fantasy. Retrieved on 2007-06-25.

These are just two examples of market share Nintendo offered up on a silver platter for anyone interested in selling their own gaming console. Enter the Playstation 1 by Sony… right place, right time.

PS3

We all know the biggest problem with the PS3. The sheer cost of the thing! Really this is Sony proving to the gaming community that they don’t deserve the space in the industry that they currently occupy. Why is it so expensive? Not really a question for this article except for two points: the infamous cell processor and Blu-ray.

Cell Processor

The cell processor is a joint effort between IBM and Sony and in all honesty the technology may be a great idea, but as good as it may be it has at least one debilitating flaw. IBM is claiming they would be “lucky” if they got a yield rate (percentage of usable processors) of 10-20% for the cell processors. This means that straight off the assembly line at least 80% of the cell processors are unusable in the PS3. Does this drive up the manufacturing cost of the PS3? It absolutely does and is at least one indication as to why it’s soooooooo expensive.

Blu-ray

Blu-ray itself is a topic that would span its own article. In the context of this discussion however Blu-ray is another piece of brand-spanking-new technology included in the latest console in the Playstation series (PS3) . There is certainly nothing wrong with having new technology in your console, but it shouldn’t be constructed completely of new technology. Not if you want to make it affordable for the consumer.

The real problem with the PS3 using the Cell Processor and Blu-Ray has nothing to do whether the technology is expensive OR new. The real problem is the impetus Sony had for putting this technology into their latest and greatest console. Let me assure you it has nothing to do with consumer benefit. Sure, in a collateral-damage-sort-of way the consumer will benefit from these technologies (putting the cost aside) but cell and Blu-ray are in the PS3 for one reason and one reason only. Sony wants to embed its technology deep into multiple areas of the technology industry. I wouldn’t even say there’s anything necessarily all that “wrong” with that when you balance it out so the consumer and company can benefit mutually. But with the cost at $600 when traditionally consumers should expect to spend at most half that, the balance is is lost and the consumer is on the losing end.

Wrap Up

Sony is a company that has done a lot of good for the electronic entertainment industry in the past. I have a 40″ Sony Trinitron TV at home that I love and before LCDs were affordable I always insisted on a Trinitron for my PC monitor as well. However, recently something in Sony has seemed to change, they appear to be losing some of their consideration for the consumer and with that on the decline it scares me that they are trying to be the source of technologies that will dominate different niches in the electronics industry going forward. Blu-ray, if it wins the HD media war will be in every home in 5 years. This is compounded by the fact that Sony owns Sony Pictures and “could” use their positioning to make their movies more available than other label’s movies. Let’s hope that doesn’t, that would be bad for us.

Powered by WordPress