-
- I’m Working on a Product.
-
Earlier this month I started working on a product. It’s nothing new. It’s pretty basic. It’s going to be really cheap. But I think it will be pretty cool. I’ll post screencasts once I finish more of the javascript. Until then, announcing this is just a tease and motivating factor. I’ve said it; now I need to go forward and finish the first version.
-
- Using Presenters in Rails
-
Sitting thrugh my first tutorials session at RailsConf we’ve come across an interesting discussion about the philosophy of using the ‘Presenter Pattern’ to refactor code in your applications controller.
-
- Blogging is not Technology.
-
Last week I was invited to speak at a local NetSquared meeting out in Tempe. Presenting on the topic of blogging forced me to take a step back to look at what I’ve been doing over the past seven years. I realized all of the technological connotations associated to blogging are irrelevant. Blogging is not about the web, rss feeds, or technology. That is just a means to an end. Blogging is about people, it’s about voices, blogging is all about you. Blogging is a medium for distributing both fact and opinion. It’s about discussion and connecting people in a relevant context. The technology just helps run the show.
-
- Less Markup Is Better Markup.
-
There is a lot of ambiguity when it comes to writing semantic markup in HTML: to what extent should we markup data? How semantically detailed do we need to be? While there is no specific rule of thumb, I will say that the less the better. When writing markup, be as clean as possible without losing meaning. Much like how The Elements of Style emphasizes brevity in writing - a sentence should use as few words as possible without losing it’s meaning - an html document should use as little markup as possible without breaking the context of it’s content.
-
- Write HTML That Means Something
-
HTML is often overlooked in development projects. Rendering errors and other visual debacles tend to shift a developer’s focus away from HTML’s actual purpose: semantics. It’s been said before but I feel we still need to emphasize the fact that HTML has nothing to do with the visual presentation of the layout we are attempting to create whether it be for the web or any other medium.
-
- Utilizing Regular Expressions in AS3
-
Regular Expressions are a powerful tool that you can utilize in many different programming languages. After throwing together the little twitter widget at the top of this page - I was informed by Brian Shaler of a major bug that causing it to crash. So while reworking the code to fix it I figured I’d add some much needed functionality as well. You see, just grabbing the feed from twitter does not generate html links for you. You have to parse your feed and wrap any ‘@username’ responses, or ‘http://addresses’ into actual hyperlinks yourself. Here’s how I did it.
-
- Simple AJAX Links With Prototype.js
-
Getting my head wrapped around Prototype.js has been a difficult process. But today I was faced with the simple challenge of creating links that could load external files into divs embedded onto the page. Nothing fancy but useful nonetheless. Here’s how I did it:
-
- Ruby: Tax Estimator
-
I got bored a couple of weeks ago and wanted to figure out how much I’d be paying in taxes depending on how much I made. I wrote this little script in Ruby to give me a basic estimate of how much I’d owe. You can use it at your own risk or make it better and share it with me!
Here is the source:
# -------------------------------------------------------------------- # Amounts to analyze taxes for. # -------------------------------------------------------------------- amounts = [40000, 50000, 60000] pto = 80 # Specify amount of hours as integer # -------------------------------------------------------------------- # Tax schedule for 2006 supplied by IRS # (http://www.irs.gov/formspubs/article/0,,id=150856,00.html) # # Arizona tax information obtained from # (http://dab.nfc.usda.gov/pubs/docs/taxformulas/formulas/statecitycounty/taxaz/taxaz.html) # -------------------------------------------------------------------- tax_rates = [0.1, 0.15, 0.25, 0.28, 0.33, 0.35] cutoff_levels = [0, 7550, 30650, 74200, 154800, 336550] pre_tax_balances = [0, 755, 4220, 15107.5, 37675.5, 97653] az_tax_rates = [0.1,0.19] az_cutoff = 10000 work_hours = 52*40-pto # -------------------------------------------------------------------- # Extend the numeric clas to accomodate formatting. # -------------------------------------------------------------------- class Numeric def to_currency sprintf("$%0.2f", self) end def to_percent sprintf("%d%", self*100) end end # -------------------------------------------------------------------- # Calculate the amounts. # -------------------------------------------------------------------- for amount in amounts # Determine the federal witholding bracket index = 0 for cutoff in cutoff_levels if amount > cutoff then bracket = index end index += 1 end # Determine the state tax withholding percentage (amount < az_cutoff) ? az_index = 0 : az_index = 1 # Calculate withholding amounts and remaining income tax = (amount-cutoff_levels[bracket])*tax_rates[bracket] + pre_tax_balances[bracket] az_tax = tax * az_tax_rates[az_index] income = amount - tax - az_tax # Print out the results puts "---------------------------------------------------------------" puts "Income Analyses for #{amount.to_currency} w/ #{pto} hours of paid time off " puts "---------------------------------------------------------------" puts "This level of income would put you in the level #{bracket+1} tax bracket which charges #{tax_rates[bracket].to_percent}." puts "In addition this income qualifies for the #{az_tax_rates[az_index]} state income tax level." puts "Total income: #{income.to_currency} after #{tax.to_currency} in federal tax expenses and #{az_tax.to_currency} in state tax expenses.." puts "------------------------------\nPost Tax Income\n------------------------------" puts "Monthly income: #{(income/12).to_currency}" puts "Bi-Weekly income: #{(income/24).to_currency}" puts "------------------------------\nHourly Income\n------------------------------" puts "You are going to work #{work_hours} hours this year." puts "That will make up #{(work_hours.to_f/(365*12)).to_percent} percent of your active time." puts "Before tax your hourly income is #{(amount / work_hours).to_currency} taking paid time off into account." puts "After tax your hourly income is #{(income / work_hours).to_currency} taking paid time off into account." puts "\n\n" end
-
- Blogging Software
-
I am growing very VERY VERY tired of wordpress comment spam! Becuase it’s so standardized and widespread it’s an open target to these attacks. Here’s an analogy.. using wordpress instead of a homebaked or less popular blogging system is like using a PC instead of a mac when it comes to viruses! Geez. Oh well this is not meant to be a rant, rather I want suggestions. What do you guys suggest I switch to?
Presently, I’m considering Mephisto. I don’t like wordpress becuase I think it’s too feature rich andheavy weight. I want something lightweight that’s easy for me to hack into and add my own code on. I truly dislike the notion of upgrading. Once I setup a blog the code is hacked apart by myself so much that upgrading just isn’t an option. So what are your thoughts? What do you recommend? Should I just build my own blogging software? Should I try out Mephisto? Are there any other decent CMS systems that are preferabbly Rails based?
-
- Ruby: Working with files and directories.
-
I wrote this snippet today to cycle through the present working directory and do some cleaning up so to speak. We got a ton of images from one of our clients and they all need to be setup as galleries for slideshow pro in flash. So I needed a few things to be done.. first of all the images were all conveniently placed in their own directories for each album, however, the thumbnails were stored together with the large photo files so I needed to separate them from each other. I wrote this snippet… my first time writing a ruby script to do some nifty stuff with directories and files quickly. This will actually rename all of the directories to be more web friendly i.e. ‘Bay Area’ becomes ‘bay_area’ etc. etc. and then it will rename all of the images uniformly but place thumbnails in a tn subdirectory and large images in an lg subdirectory. Finally, it also generates a SSP friendly XML doc for each directory.
# Gallery creator.. # This ruby file should be placed into the working directory # containing all of the directories you wish to be converted # into galleries. # USER DEFINED SETTINGS # ---------------------------- # ignore: # Array of directories you wish to ignore.. i.e. parent, and current. ignore = ['.','..'] # large_id: # A string used to identify images to be moved into the large directory. large_id = "555" # small_id: # A string used to identify images to be moved into the thumbnail directory. small_id = "72" # SCRIPT BEGINS: # Don't change unless you really want to. # ---------------------------- # Initialize directory object... directory = Dir.new(Dir.pwd) # Cycle through directory directory.each do |d| # Only go through directories and ignore directories specified by user. unless File.ftype(d) != "directory" or ignore.include?(d) # Jump into directory and parse files. Dir.chdir(d) Dir.foreach(Dir.pwd) do |f| # Create directories for thumbnails or large images. %w(tn lg).each do |newdir| unless File.exists?(newdir) Dir.mkdir(newdir) end end # Cycle through files. unless File.ftype(f) != "file" # Create new file name and set target directory. if f =~ /#{large_id}/ newname = f.split(large_id.to_s).each{|i| i.downcase!}.join("") newdir = "lg" elsif f =~ /#{small_id}/ newname = f.split(small_id.to_s).each{|i| i.downcase!}.join("") newdir = "tn" else newdir = nil end # Open the old file... oldfile = File.new(f) # Jump to large directory if possible. unless newdir.nil? Dir.chdir(newdir) # Write new file if it doesn't exist. unless File.exists?(newname) File.open(newname,"w+") do |n| n.write(oldfile.read) end end # Move back and delete the old file. Dir.chdir("../") File.delete(f) end # Log event. puts "Renamed: #{f} to #{newname} moved to '#{newdir}'" end end # Return to parent Dir.chdir("../") # Rename to web friendly urls. newdir = d.split(" ").each{|i| i.downcase!}.join("_") File.rename(d,newdir) # Build the XML docs. xml = "< ?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n dir_for_xml = Dir.new(”#{newdir}/lg/”) dir_for_xml.each do |filename| unless ignore.include?(filename) then xml += ”\n” \n” end end xml += “\n” File.open(”#{newdir}.xml”,”w”) do |n| n.write(xml) end end end
In my case it’s important to note that the files were grouped together with names like: ‘torrey-ridge555_1.jpg’ and ‘torrey-ridge72_1.jpg’. Detecting the ‘555′ or ‘72′ safely solved the problem in my case ofcourse there could be some situations where something this easy could backfire. To make the file names uniform I simply split the file by the identifier and joined it back together.