<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>im.ralphholzmann</title><generator>Tumblr (3.0; @ralphholzmann)</generator><link>http://blog.ralphholzmann.com/</link><item><title>jQuery Required Form Validation</title><description>&lt;p&gt;Recently I was asked to create a web form for my internship that had about 30 text input fields. All fields were required, and they asked that form have a validation check. So, instead of writing 30 individual checks for each input, I wrote a some jQuery.&lt;/p&gt;
&lt;p&gt;First of all, your required form text inputs must look like this:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;input type="text" title="Input Title" class="required" /&gt;
&lt;/pre&gt;
&lt;p&gt;Notice how the required text inputs have the class “required”. Here is the form validation function that gets called when the form tries to submit:&lt;/p&gt;
&lt;pre class="code"&gt;function validate() {

	// Initialize empty string for errors
	var errors = "";

	// Trim whitespace before and after every input
	$('input:text').each(function(){
		$(this).val($(this).val().trim());
	});



	// Check if all required inputs are empty
	$('.required').each(function(){
		if($(this).val() == "") {
			errors += "&lt;li&gt;" + $(this).attr("title") + " cannot be blank&lt;/li&gt;";
  		}
	});
	
	// If there are no errors, submit the form, otherwise display errors.
	if(errors == "") {
		return true;  	
	} else {
  		$('#errors').html("The following errors occured: &lt;ul&gt;" + errors + "&lt;/ul&gt;").slideDown();
  		return false;
	}
}&lt;/pre&gt;
&lt;p&gt;Which uses this prototype function for Strings I call trim. It trims the whitespace from the beginning and end of any String.&lt;/p&gt;
&lt;pre class="code"&gt;String.prototype.trim = function () {
	return this.replace(/^\s+|\s+$/g,"");
}&lt;/pre&gt;
&lt;p&gt;The first line initializes an errors String to hold any errors that may occur&lt;/p&gt;
&lt;p&gt;The next function takes the value of each input (of type text), trims the whitespace from it, and then replaces it with the trimmed version. This stops the user from simply entering a few spaces in an input to circumvent required fields.&lt;/p&gt;
&lt;p&gt;The next function selects all fields with the class “required”, then for each input, it checks if its value is empty. If it is, it grabs the title of that input and uses it in the error message.&lt;/p&gt;
&lt;p&gt;Finally, if there are no errors, the function returns true and the form is submitted. Otherwise, the errors are displayed and the form is not submitted.&lt;/p&gt;
&lt;p&gt;This nifty little function not only saved me a ton of time, but also a lot of lines of tedious coding. I hope this helps save you some time too!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.ralphholzmann.com/tumblr/required.html" target="_blank"&gt;Click here for a working demo&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.ralphholzmann.com/post/72816531</link><guid>http://blog.ralphholzmann.com/post/72816531</guid><pubDate>Sat, 24 Jan 2009 10:38:00 -0600</pubDate></item><item><title>What I learned about C++ STL vector::erase</title><description>&lt;p&gt;In file structures this week we had an assignment to implement &lt;a target="_blank" title="LZ77 compression" href="http://en.wikipedia.org/wiki/LZ77_and_LZ78"&gt;LZ77 compression&lt;/a&gt; using a custom bit by bit input/output class. This resulted in having to read/write individual bits, using boolean &lt;a target="_blank" title="vectors" href="http://www.cplusplus.com/reference/stl/vector/"&gt;vectors&lt;/a&gt;. I would pull individual bits off of the front of the vector, decode them, and then delete them from the &lt;a title="vector using erase" href="http://www.cplusplus.com/reference/stl/vector/erase.html" target="_blank"&gt;vector using erase&lt;/a&gt; like this:&lt;/p&gt;
&lt;p&gt;someBooleanVector.erase(someBooleanVector.begin(), someBooleanVector.begin() + length);&lt;/p&gt;
&lt;p&gt;This worked well for very small text files, but took FOREVER on larger text files (like the hamlet text file that was included with the assignment). After doing a ton of testing, I narrowed it down to the .erase function calls. Then, after googling some information about vectors, I learned that .erase doesn’t simply erase the first &lt;i&gt;x&lt;/i&gt; amount of elements. What it does is &lt;u&gt;clear&lt;/u&gt; the first &lt;i&gt;x&lt;/i&gt; amount of elements, and then &lt;u&gt;shifts&lt;/u&gt; all the remaining elements down to the front of the vector, then edits the vector.size() accordingly.&lt;/p&gt;
&lt;p&gt;This was costing my program a ton of runtime. A program that was supposed to take less than a second to run, was taking 17 seconds to run. The reason was the &lt;i&gt;shifting&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;For example, at capacity, my boolean vector would have 32,768 elements. If I deleted one element from the vector, it would have to perform 32,767 shifts, costing my program a ton of runtime.&lt;/p&gt;
&lt;p&gt;I simply fixed this by completely reversing the way I constructed the boolean vector, then using the much more efficient &lt;a target="_blank" title=".back()" href="http://www.cplusplus.com/reference/stl/vector/back.html"&gt;.back()&lt;/a&gt; and &lt;a target="_blank" title=".pop_back()" href="http://www.cplusplus.com/reference/stl/vector/pop_back.html"&gt;.pop_back()&lt;/a&gt;, which require no shifting, to access and delete records. This sped up my program from 17 seconds to half a second.&lt;/p&gt;
&lt;p&gt;I hope reading this helps someone out there who may have runtime issues with vectors.&lt;/p&gt;
&lt;p&gt;Have a good weekend.&lt;/p&gt;</description><link>http://blog.ralphholzmann.com/post/56138672</link><guid>http://blog.ralphholzmann.com/post/56138672</guid><pubDate>Fri, 24 Oct 2008 10:09:00 -0500</pubDate></item><item><title>Portfolio</title><description>&lt;p&gt;I added a link to my portfolio of web design projects to the left. Check it out and tell me what you think&lt;/p&gt;

&lt;p&gt;ralphholzmann@gmail.com&lt;/p&gt;
&lt;p&gt;~Ralph&lt;/p&gt;</description><link>http://blog.ralphholzmann.com/post/53516991</link><guid>http://blog.ralphholzmann.com/post/53516991</guid><pubDate>Tue, 07 Oct 2008 16:40:30 -0500</pubDate></item><item><title>Finding P and Q in an RSA encryption</title><description>&lt;p&gt;Our last assignment in &lt;a target="_blank" title="File Structures" href="http://www.uwosh.edu/faculty_staff/furcyd/cs321/"&gt;File Structures&lt;/a&gt; dealt with decrypting messages ecrypted with &lt;a target="_blank" title="RSA" href="http://en.wikipedia.org/wiki/RSA"&gt;RSA&lt;/a&gt; and a &lt;a target="_blank" title="Vigenère cipher" href="http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher"&gt;Viginere cypher&lt;/a&gt;. &lt;a target="_blank" title="Our professor" href="http://www.uwosh.edu/faculty_staff/furcyd/dave.gif"&gt;Our professor&lt;/a&gt; stressed that we should come up with the most efficient way of finding primes p and q given n, because that would require the most time and he would take points off for decrypters that take more than 10 seconds to run. Considering the assignment was due 5 minutes ago, I’m going to post my algorithm for finding P and Q which I’m pretty proud of because it runs really fast.&lt;/p&gt;
&lt;p class="code"&gt;// Recursively tries to find prime numbers, &lt;br/&gt; // p and q, given n, starting each factor &lt;br/&gt; // at the square root of n. Values p and q are &lt;br/&gt; // passed by reference so I wouldn’t have to &lt;br/&gt; // return an array or anything&lt;br/&gt; void findPQ(unsigned long n, int up, int down, unsigned long&amp; p, unsigned long&amp; q) { &lt;br/&gt;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;bool    foundUp, foundDown = false;&lt;br/&gt;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;// Finds lower prime from root&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;while (!foundDown){&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;if (!isPrime(down)) {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;down—;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;} else {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;foundDown = true;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;}&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;// Finds upper prime from root    &lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;while (!foundUp){&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;if (!isPrime(up)) {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;up++;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;} else {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;foundUp = true;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;}&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;// Checks primes p and q against n&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;if( down &gt; 0 &amp;&amp; up &lt; 65535) {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;if ((up * down) == n) {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;p = up;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;q = down;&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;} else if ((up * down) &lt; n) {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;findPQ(n, (up + 2), down, p, q);&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;} else {&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="threetabs" height="1" width="1"/&gt;findPQ(n, up, (down - 2), p, q);&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="twotabs" height="1" width="1"/&gt;}&lt;br/&gt;&lt;img src="http://ralphholzmann.com/tumblr/images/spacer.gif" alt=" " class="onetab" height="1" width="1"/&gt;}&lt;br/&gt; }&lt;/p&gt;
&lt;p&gt;My decrypter can decrypt Hamlet in less than a second!&lt;/p&gt;
&lt;p&gt;Have a good weekend.&lt;/p&gt;
&lt;p&gt;~Ralph&lt;/p&gt;</description><link>http://blog.ralphholzmann.com/post/51867551</link><guid>http://blog.ralphholzmann.com/post/51867551</guid><pubDate>Fri, 26 Sep 2008 09:07:00 -0500</pubDate><category>C++</category><category>RSA</category><category>Algorithm</category><category>Decryption</category><category>Encryption</category></item><item><title>Redesign (sort of)</title><description>&lt;p&gt;I just got done recoding my blog, and this is my first post! Luckily, this time I integrated my design with Tumblr, so it will be a lot easier to make posts. There are still some bugs to work out, which I’ll be pounding out in a couple days, but let me know what you think!&lt;/p&gt;
&lt;p&gt;~Ralph&lt;/p&gt;</description><link>http://blog.ralphholzmann.com/post/51416979</link><guid>http://blog.ralphholzmann.com/post/51416979</guid><pubDate>Tue, 23 Sep 2008 11:53:57 -0500</pubDate></item></channel></rss>
