Archive for category web development
Algebra in the Real World
Posted by Byron Sorrells in web development on May 25, 2010
When are we ever going to use this?!
How many times did you say that in school? I happen to be about 500x more stubborn than the average person. As a result, I said it nearly every day. Diagramming sentences? The date that Sam Houston pulled the sheets over Santa Anna? Algebra? To all of these, I really, truly wondered when on God’s green earth I would use them.
I am building a website that is based on an investment portfolio. The equation wasn’t really that difficult, but I had write it down to sort it out.
Let’s say I have 6 securities with various share volumes that comprise a my portfolio. Let’s say you have $362,500 and you want to mimic my portfolio. How do you figure out how much of each share to buy? Let’s start with what we know:
| Security | Volume | Price |
|---|---|---|
| AAPL | 1500 | $250.00 |
| MELI | 1000 | $50.00 |
| CERN | 2500 | $90.00 |
| T | 5000 | $25.00 |
| GOOG | 500 | $475.00 |
| CTRP | 750 | $38.00 |
So, I first figured out the total amount of the portfolio that I started with:
Volume * Price for each security = $1,041,000
The portfolio that wants to mimic this portfolio has $362,500. So, next we figure out what percentage our mimicked portfolio is of the original one:
($362,000 / $1,041,000) * 100 = 34%
That left me thinking I just needed to multiply the share volumes by 34% in order to mimic the starting portfolio:
| Security | Volume | Price |
|---|---|---|
| AAPL | (1500*.34) = 510 | $250.00 |
| MELI | (1000*.34) = 340 | $50.00 |
| CERN | (2500*.34) = 850 | $90.00 |
| T | (5000*.34) = 1700 | $25.00 |
| GOOG | (500*.34) = 170 | $475.00 |
| CTRP | (750*.34) = 255 | $38.00 |
For all you math wizards and adults, I am aware this is not rocket science. However, it does show that there’s a need for basic algebra skills outside of the classroom. p – 1 = 5p +3p – 8 doesn’t really look like much in a classroom. I’m a firm believer that more US schools should teach using real world examples. Make it fun.
This might be the lamest post I’ve ever written, but I actually got excited when I realized I had used some form of algebra to solve the equation.
Reloading an iFrame with jQuery
Posted by Byron Sorrells in web development on June 2, 2009
I came across a scenario today at work (nycgo.com) where I needed to refresh ads on a page without refreshing the entire page. The ads were already sitting in iFrames, so that was a big help. Using jQuery, you only need a few lines.
In my particular situation, I want to reload the ads every time a user clicks on certain links. Give the links a class of reloadAds and then insert the following into your $(document).ready function:
$(".reloadAds").click(function() {
jQuery.each($("iframe"), function() {
$(this).attr({
src: $(this).attr("src")
});
});
return false;
});
This will loop through each iFrame every time you click on a link with a class of reloadAds and set the source of the iFrame to itself… thus reloading the iFrame and returning a new ad.
Pretty easy, huh?
As noted below in the comments, your iFrame might be cached. You can append a random variable to the source if you want to request a new URL that is essentially the same.
Reinventing the Wheel
Posted by Byron Sorrells in web development on May 28, 2009
A lot of people ask me what I do. I usually respond with something like, “Programming.” If I want to get really specific with someone, I’ll say, “Web development.” I don’t find that it’s usefull to go much further than that.
I’ve done a lot of things in my thirteen years of working. In chronological order: BBQ Restaurant, Golf Course, Lawn Maintenance (self-employed), Foley’s (now Macy’s), Web Development (Perl), Musician, Dillard’s, Nordstrom, Mortgage Sales, Real Estate Rentals (in Manhattan – gross), Nordstrom again, EMR Software, and currently, Web Development for the City of New York. If you’re not into “computer stuff,” you can stop reading right here.
I’ve been working on a project for a couple of months that has been very educational and should be very beneficial once complete. I titled this post reinventing the wheel, because in way I am. I was tasked with completing the development portion of the enhancements to the nycgo.com site search. As of now, we use a Google Search Appliance. It crawls our site and indexes documents much like the Google crawlers that index the entire web. It returns results in .10 seconds, just like Google does. It serves up relevant content based on the keywords you typed in, but that’s about where it stops. The box, which isn’t cheap, has a nice administrative interface that allows for a lot of customization, but the Google Search Appliance is a tool for a particular type of search. It’s not meant to solve every type of search need.
Just before I was assigned the search project, I started reading Information Architecture for the World Wide Web. This book is an incredible resource for understanding how large scale web sites are planned and developed. In chapter 8 on search, the authors mentioned Endeca as a leader in the field of guided navigation. I immediately thought, “Great! My problems are solved! I’ll just download it and ‘turn it on.’” It turns out Endeca is quite expensive, but rightfully so. Endeca powers the search functionality at Home Depot, Wal-Mart, Borders, NY Magazine, Menu Pages, Auto Trader, HMV, and Lonely Planet. That’s just a small sampling. Their technology for guided search is far beyond that of Google. I’m sure it won’t be too much longer before Google makes a effort at entering the market of faceted search.
After learning that our GSA was no longer an option and that we wouldn’t be forking out $200,000+ for Endeca, I set out to reinvent the wheel of guided search for our web site. I won’t go into any painstaking detail, but I’ll outline the steps I took in order to create a similar search tool that was efficient as possible. We use ColdFusion (don’t ask!) wrapped in ModelGlue with SQL Server 2005.
- Write a stored procedure that will assimilate all content to be searched (UNION ALL from multiple sources into one).
- Choose whether FREETEXTTABLE OR CONTAINSTABLE is better – I chose to use CONTAINSTABLE.
- Write a single stored procedure that accepts a free text query along with taxonomy ids to filter content.
- Allow multiple taxonomy ids to be passed in. I.e.: T=123|456|789|105
- Return multiple result sets: a) matched content items b) taxonomy for matched content
That’s a few months of work condensed into five simple steps, so it’s obviously simplified. I would be writing for weeks if I tried to document the entire thing. I would say that the biggest gains in efficiency come from using a single stored procedure and properly indexing the tables. The SQL Server tuning advisor can guide you in the right direction, but understanding indexes is essential to speed. The search won’t launch for another couple of months, but I’ll be sure to put a link to it when it does. It should facilitate finding material on our site and allow people to browse easier.
If anyone reads this and happens to have questions, I would be happy to answer them!
