I’m sure the serialization inefficiencies could be waved away with a layer of arithmetic coding compression using a specialized model trained on the wasted bits of this format, but I worry that this is just basically sweeping technical dust under the rug …and overengineering for such a trivial problem. :(
Kevin Li Li Ken un
Posts
-
When Poor Design Gets Baked Into a File Format -
When Poor Design Gets Baked Into a File FormatFound this nugget in the constructor of a class that’s supposed to represent a structure in a binary file:
var isNamed = reader.ReadBoolean(); // This byte indicates whether the object has a name.
if (isNamed) // If the object has a name, read the remaining bytes.
{
var nameLength = reader.ReadByte(); // This byte indicates the length of the name.
this.Name = new string(reader.ReadChars(nameLength));
}The property setter for ``Name`` checks the length of the string—and it forbids zero-length strings. :wtf: Wouldn’t a name length value of ``0`` suffice to indicate the absence of a name?
-
Is this madness? The pursuit of single-statement methodsMy code started out as something fairly easy to follow like this:
void RemoveDuplicatesButton_Click(object sender, RoutedEventArgs e)
{
// Create a set to hold a collection of lines that have already been processed.
SortedSet seen = new SortedSet();
// Create a StringBuilder to avoid the performance penalty of concatenating strings repeatedly.
StringBuilder stringBuilder = new StringBuilder();
// Split the text from the text box by lines and examine each one.
foreach (string line in this.InputTextBox.Text.Split(new char[] { '\r', '\n' }))
{
// If the string is successfully added to the set, then it has not been processed before.
if (seen.Add(line))
{
// Add the line to the output.
stringBuilder.AppendLine(line);
}
}
// Build the string and assign it to the text box.
this.InputTextBox.Text = stringBuilder.ToString();
}Then I factored out some of the code into extension methods, removed the unnecessary curly braces, and got this:
void RemoveDuplicatesButton_Click(object sender, RoutedEventArgs e)
{
// Create a StringBuilder to avoid the performance penalty of concatenating strings repeatedly.
StringBuilder stringBuilder = new StringBuilder();
// Split the text from the text box into a collection of unique lines.
foreach (string line in this.InputTextBox.Text.SplitLines().Unique())
// Add the line to the output.
stringBuilder.AppendLine(line);
// Build the string and assign it to the text box.
this.InputTextBox.Text = stringBuilder.ToString();
}And then I took it a step further.
void RemoveDuplicatesButton_Click(object sender, RoutedEventArgs e) =>
// Take the text from the text box, split it by lines, remove the duplicates, and assign the results to the text box.
this.InputTextBox.Text = this.InputTextBox.Text.SplitLines().Unique().Aggregate(
new StringBuilder(),
(StringBuilder stringBuilder, string line) => stringBuilder.AppendLine(line),
(StringBuilder stringBuilder) => stringBuilder.ToString());And the one-liner:
void RemoveDuplicatesButton_Click(object sender, RoutedEventArgs e) => this.InputTextBox.Text = this.InputTextBox.Text.SplitLines().Unique().Aggregate(new StringBuilder(), (sb, line) => sb.AppendLine(line), sb => sb.ToString());
I get great joy a
-
USB 2.0 Coexisting With USB 3.0 Despite USB 3.0 Being Backwards-compatibleI've been looking for new hardware to build a mini-ITX server. USB 3.0 support is a must as are SATA 6.0Gb/s, ECC DDR3 RAM, and gigabit Ethernet. Disappointingly, no such motherboard exists with all the features described. Instead, after so much browsing and searching, I've noticed how so much hardware out there are USB 3.0-enabled and curiously, despite USB 3.0 being backwards-compatible with its predecessors I find that computer cases and motherboards will almost always have USB 2.0 ports coexisting with the newer USB 3.0 ports. If USB 3.0 is the new standard and is backwards-compatible, why half-ass the hardware by providing "crippled" ports adjacent to the super speed ones? I'm just curious since I have been coming across computer cases with both USB 3.0 and 2.0 ports.
-
Full Disk Encryption for Ubuntu Linux: How?I actually have TrueCrypt working on my other Ubuntu installations, but they just protect the files and not the entire system[^]. It's one reason TrueCrypt isn't an option. For my Windows BitLocker setup, I built the entire system myself. I couldn't find any motherboard with a TPM, so I had to make a few group policy changes as an administrator to force BitLocker to work without it. Using the command line tools for managing BitLocker, I made it deposit the boot key in the 100MiB system partition; since the system partition resides on a removable medium there's nothing an attacker can tamper with on the hard drives but pure "random" bits. As for the setup I'm trying to achieve, Linux's dm-crypt is pretty much the only free and flexible solution that I know of that allows for it. In fact, I've gotten as far as make it work like in the diagram[^] (2-factor authentication and all) except it asks for the password 4 times (once for each partition). It's quite annoying and an issue that I'm willing to investigate how to eliminate in an otherwise perfect setup.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
Getting the URL Minus the Query StringI did some testing, and it appears that certain values in the query can replace
$1
in .htaccess with just 406.shtml or 406_shtml. mysite.com/a/b/c?d=1&e=2&� will cause this problem. It looks like I will have to parse the contents of$_SERVER['REQUEST_URI']
within the script if I want to handle all the cases without fail.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
Getting the URL Minus the Query StringInterestingly enough, I get all the pieces of the request neatly delimited by ampersands. mysite.com/a/b/c?d=1&e=2&request=3
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=1&e=2&request=3"
Request ($_GET["request"]): "3"
Request ($_SERVER["QUERY_STRING"]): "request=index.php&request=a/b/c&d=1&e=2&request=3"
d="1"
e="2"mysite.com/a/b/c?d=1&e=2&request=%26+%3F
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=1&e=2&request=%26+%3F"
Request ($_GET["request"]): "& ?"
Request ($_SERVER["QUERY_STRING"]): "request=index.php&request=a/b/c&d=1&e=2&request=%26+%3F"
d="1"
e="2"Although the key-value pairs remain encoded, I guess it's still better to just use
explode
to get the key-value pairs first and thenexplode
the resulting items to get the keys and values.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
Getting the URL Minus the Query StringAt the moment, I have index.php located at the root. I want to have it parse all my URLs and delegate the workload to the correct code (via URL rewriting). I may be a bit nit-picky, but I'd like to know if there's an elegant solution to neatly separating the request URL and the key-value pairs of the query? My index.php looks like this:
If I give it some URLs, they produce the corresponding outputs:
-
mysite.com/a/b/c?d=1&e=2&request=3
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=1&e=2&request=3"
Request ($_GET["request"]): "3"
d="1"
e="2" -
Debug Output
Request ($_SERVER["REQUEST_URI"]): "/a/b/c?d=3&e=4"
Request ($_GET["request"]): "a/b/c"
d="3"
e="4"
$_SERVER["REQUEST_URI"]
includes everything after mysite.com including the raw query string, and$_GET["request"]
will not return the requested URL minus the query string if there is a key namedrequest
. I could parse the value of$_SERVER["REQUEST_URI"]
myself, but I'd like to use built-in functionality before coding around the problem.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
-
Full Disk Encryption for Ubuntu Linux: How?I've read the first two before posting, but the third one pretty much describes the same thing. The problem I have with the official installer's behavior is that it requires typing in a password for every single encrypted device even and doesn't give the option to use a single password to decrypt all of them—hence my desire to introduce a "key partition" in a removable medium to handle automatically decrypting them; I would only have to type in the password for the key partition achieving a convenient 2-factor authentication setup.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
Full Disk Encryption for Ubuntu Linux: How?So, I've got a system equipped with a card reader (that I can boot from), a solid-state drive, and 2 conventional hard drives. I want to install Ubuntu on it and have all of it (except the boot partition because it can't) be fully encrypted. Just so there's no confusion here:
- Full disk encryption: the use of disk encryption software or hardware to ensure that every (or almost every) bit persisted in storage is encrypted and unreadable to unauthorized users. That means anything on the disk that can be covered by encryption will be covered by encryption.
- Linux newbie: Yes. That's me.
- The setup I'm trying to achieve: (Click to see the diagram. [^])
I've already done this successfully using Windows BitLocker on the same system (though I had to apply some blunt-force trauma to get it to do what I want, and it boots without prompting for a password). The same seems to take a bit more work under Ubuntu since the official installers won't perform full-disk encryption without forcing me to type the same passphrase for every partition that needs to be decrypted. From what I've read elsewhere, I've got a general idea what I have to do (install normally, move directories, change mount points, modify fstab and cryptab), but nothing concrete.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
Disk Imaging Software; Recommendations?I use the Ubuntu discs in trial mode (where it boots into a useable OS that just works without touching your hard drive). It has no problems reading various partition types, file systems, or working with AHCI. Most network interfaces are supported without doing anything more so if you have a network location you'd like to backup to, this is one way to do it. From Ubuntu, I just use the terminal to do my imaging.
- Backup and Compress: dd if=the_device_you_want_to_backup bs=blocksize_in_bytes conv=noerror | gzip -c -9 > path_and_filename
- Document the Device Metrics: fdisk -l the_device_you_want_to_backup > path_and_filename
- Decompress and Restore: gunzip -c path_and_filename | dd of=the_device_you_want_to_restore_to conv=noerror
- If you have an uncompressed image, you can even mount it for viewing or for reading and writing. The options depend on how you backed it up, but you can mount partitions from within an entire drive image or individual partition images (if you backed up each partition into its own file).
The device to backup is typically /dev/sda (the entire contents of the first physical hard drive), or /dev/sda1 (the first partition on the first physical hard drive). If you're backing up to external media like a USB drive or a SDHC card, the path to the media is usually /media/volume_name/. bzip2, pigz (parallel GZip implementation), pbzip2 (parallel BZip2 implementation), lzop (extremely fast compression and decompression), and xz (LZMA compression) are all drop-in replacements for GZip; adjust the arguments accordingly. I'm a Linux terminal newbie, so please check the commands carefully before applying. The DD tool has been jokingly referred to as "disk destroyer." (Hint: if ≠ of) I hope this helps. :) By the way, did you really want to restrict your options to DOS tools?
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
No More Improvement Possible: When Software Becomes Monstrous and BloatedYes, they already do that but some features are just so useless, if they followed your pattern:
- Nero Burning ROM would have to be free and have basic burning capabilities. They already have such a free version (and it sucks a lot): http://download.cnet.com/Nero-9-Free-Version/3000-2646_4-10964576.html[^].
- They would release only point updates to Nero Burning ROM for years at a time.
- Every significant package of advanced capabilities (e.g., an entire set of DVD Video authoring functions, a media player or theater program, or the virtual image drive) would come in a plug-in format.
- Nero would give away minor updates every few months and sell new plug-ins with new functionality every year or so.
Then again, wouldn't it hurt their pockets? ;P
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
No More Improvement Possible: When Software Becomes Monstrous and BloatedI bought myself a copy of WinRAR instead since they seem to be offering a lifetime of free upgrades; it does everything better than WinZip (that WinZip should have had). I keep 7-zip by my side as well for the compression efficiency.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
No More Improvement Possible: When Software Becomes Monstrous and BloatedIt reminds me of an early version of Nero Burning ROM (combined with a label maker). :) The interface could be more polished though.
Reelix wrote:
switch to a free alternative that's 50x smaller!
You understated the size savings. 382.14 MB is about 130 times bigger than 2.93 MB. Then again, who would want this[^]? ;P
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
Looking for suggestions for dealing with stupid peopleMaybe they're so stupid, there is no physical way to degrade your own intelligence to their level. :)
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
No More Improvement Possible: When Software Becomes Monstrous and BloatedA decade ago, there used to be a piece of software by the name Nero Burning ROM. It was an excellent piece of software with each version better than the next. Then version 5 came out, and it dragged along its newly born younger siblings like the Wave Editor and Cover Designer. And by version 7, the software got even more popular because by then it was able to do all the things people wanted it to do: rip, edit, create, and author original content; do pretty much anything with CDs, DVDs, and Blu-ray Discs; and even backup an entire system. Nero 6 and 7 were must-have software. But it went downhill from there. By version 8, there were little—if any—major improvements that people cared about. I bought a copy of Nero 8 while it was on sale (the day before Nero 9 was released). Among the improvements were: create surround-sound audio tracks, play content with the XBOX 360 and PS3, more format support for the media player, play video with hardware acceleration, and menu editing for Blu-ray authoring. Very few of them were compelling features warranting another $50 payment for an upgrade, although surround-sound authoring, menu authoring for BDs, and hardware acceleration support sounds good for some people who edit or author their own content. Then Nero 9 came out. Let's look at what Nero 9 can do that Nero 8 could not:
- Convert PowerPoint presentations to video
- Automatic backup functions
- Extract music from music TV shows to MP3
- MP3 Pro encoding (without having to buy a plug-in)
- Create play lists
- Automatically retrieve music information from GraceNote
- A separate display window to display music information while playing music
- Shuffle play lists
- Listen to web radio and podcasts
- Play audio and video in Nero StartSmart
- Play FLAC and AIFF files
- Archive movies to flash storage (e.g., USB sticks)
- "Smart" encoding for Blu-ray (vague)
- Apply styles to video projects to automatically make the movie great
- Detect commercials
- Boost quality of standard definition videos to high definition
- Preview screen for authoring projects
I just got a promotional e-mail today from Nero telling me about how great Nero 9 is compared to Nero 8 and that I should pay $49.99 for the new version. You can tell from the list that 85% of the new features aren't even worth mentioning. Can anyone honestly say (with a straight face) that these are compelling reasons for an upgrade?
-
A simple questionFlustrated wrote:
There are some things about English spelling that could be cleaned up, but the general problem is that English is phonetically complex, so a comprehensive cleanup is impossible, and this discourages minor cleanups. For example, English has 50 different sounds, while Spanish has only 30, so English overloads the alphabet.
Nope. It's not impossible. It's being done already, just not formally. I've seen almost illiterate students from my English class in college (please suspend your disbelief) write an entire essay by spelling out words phonetically and with some "IM speak." Not surprisingly, the professor embarrassed him by whispering loud enough just so the entire front row of students could hear her (although probably not intentional). The academic world is just too attached to the oddities of the English language to let it change on its own. The fact that it can't change is because there are many institutions that enforce the current ways. There is an air of accomplishment to knowing something more difficult, and many people are not willing to lose that. It's the same reason why the upper class Koreans resisted changing to a phonetic representation of its language for centuries and instead stubbornly stuck to Chinese characters. The alphabet is a different story. We could incorporate some of the runic alphabet back into English (e.g., thorn), or take things from the International Phonetic Alphabet (which would also serve to help its learners learn other languages as well).
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
A simple questionMember 3333482 wrote:
Japanese has four alphabets.
The Japanese languages doesn't utilize an alphabet. It utilizes three writing systems, of which two are phonetic syllabaries (native inventions) and one logographic (from Chinese).
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
A simple questionSterlingCamden wrote:
G wasn't in the original Latin alphabet -- it was added later to distinguish from the sound of C. Greek had gamma (from the Semitic gimmel), but G is an unrelated development.
It was also derived from the "C", hence the glyphs' similarities.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!
-
A simple questionDoes anyone agree that an English pronunciation engine's code would have a lot of stacked and nested "if" statements? I'd throw a couple of "switch"/"case" statements in there too for the sake of words that defy enough rules to fail the logic tests in all the "if" statements.
My GUID: ca2262a7-0026-4830-a0b3-fe5d66c4eb1d :) Now I can Google this value and find all my Code Project posts!