google and crappy spam sites
Posted by Ed in Uncategorized on April 24th, 2010
Google is an indispensable tool in getting information and answers when programming. Of course many other programmers must feel the same way which makes it a desirable goal to target this group.
I used to think the “experts exchange” was a sleazy way to get high on google search results, but at least I quickly figured out how to ignore that site, or if nothing else turned up, to scroll past the parts of the page that make it appear to be a paywalled site.
Recently I noticed a new class of crap results turning up (and experts exchange dropping in the page rankings). I haven’t figured out what the deal is with codeweblog, but it is really starting to piss me off.
There have always been sites that steal content from other sites or documentation and repackage it so that when you’re looking for some technical bit of info, their site appears and thus some revenue (from google most commonly) from the page views results. But FFS codweblog comes up in a search with exactly the keywords you’re looking for but when you read it, it seems that not only do they steal content from other sites, they do some sort of randomization or translation on it so that it looks to google to be fresh content, when actuality it’s completely useless and incomprehensible (not unlike some of my blog posts).
Bah. Google fix this pleeeeese. ban that crap site forever.
Addition: I love this comment on the codweblog site that I just found.
Why bother cluttering up the intertubes with the above? It is either written by an insane person, or a really bad machine translation … Either way, it is absolutely useless.
top learning sites
Posted by Ed in Uncategorized on January 15th, 2010
Here’s a list of sites I like to use on a regular basis that are great for keeping up with the state of the art.
Solving problems
Posted by Ed in programming on December 22nd, 2009
Reading an interesting wired article about how scientific inquiry works, and it reminded me of how I solve some thorny problems.
Back in the usenet days, there were programming boards that people would ask questions, and other people would answer out of the goodness of their hearts. I found that if I had a problem I couldn’t crack, by writing it down in a manner that I would post to a public forum, it forced me to clearly think about the problem and my assumptions and 9 times out of 10 I would figure it out. Simply from the act of clearly writing down the problem space, it clarified the solution.
security notes for linux
On my ubuntu server, I used to check the auth logs occasionally just to make sure there wasn’t any suspicious activity. A couple months back, I installed denyhosts which automatically puts a block on any host that tries to login via ssh too many times with failures. As a bonus, it also can send an email with information on the blocked host.
Tonight I noticed new host that was blocked, and I was curious so I went down to the server which is behind a router/firewall and took a look to look and laugh at the failed attempts to break into my system. I was suddenly concerned when I noticed one of the hosts that was blocked was attempting to login with my login id. WTF!?
Usually an attack is randomly based. Some script will try to attack root (which is waste of time on debian systems) and then a bunch of system ids, then for good measure some common user ids such as bob.
No this attack that was thwarted actually used my login id. Creepy. My first thought was that someone had been sniffing an ssh session from a host, or a web session. But that didn’t make any sense. So I asked the google for help and got this great link. http://www.ubuntugeek.com/list-of-security-tools-available-in-ubuntu.html
After installing a few tools (zenmap is great!) I started investigating the source of attack. Long story short, the attacking machine was one of our store servers that was running an old version of software that we can’t be chuffed to upgrade yet. It was failing to open up an ssh tunnel that used to work, but no longer did, due to an operating system upgrade on the ‘attackee’
Anyhow, a fun way to spend a couple of hours, getting re-acquainted with network security.
stupid bugs during development
Posted by Ed in programming, rails, stupidity on September 21st, 2009
This always happens to me and I suspect many others. I’m going to write down some of the more aggravating things I run across, so that you can laugh at me and possibly learn from my mistakes.
Todays stupid bug:
Nested Attributes
Nested attributes are a very cool and easy way to handle object updates. Things you need to keep in mind:
- fields_for – Make sure you call fields_for on the form_for object
- accepts_nested_attributes_for – (this is what bit me) don’t forget to have this declaration in your model. Otherwise the formbuilder.object will be nil
fields_for example:
<% form_for @some_object do |form | %>
<%= f.text_field :some_field %>
<% form.fields_for :nested_obj do |nested_form| %>
<%= nested_form.text_field :attr1 %>
<% end %>
<% end %>
So the stupid thing was that I was so used to using fields_for without anything in front of it, my muscle memory skipped it, and I was puzzling over why it wasn’t working.
accepts_nested_attributes_for example:
In my_model.rb: class MyModel < ActiveRecord::Base has_many :items accepts_nested_attributes_for :items end
In my defense, I was working with namespaced controllers and namespaced models with about a dozen of them flying around. Missing the accepts_nested_attributes_for caused a subtle failure but I couldn’t see from the diagnostic messages, wasting a couple of hours and causing much frustration.
All this is well documented by the rails docs and in this blog post. I was just being stupid.
cucumber testing glitch with subdomains
Posted by Ed in programming, rails on September 15th, 2009
A note that may help others if using subdomain_fu and cucumber.
While webrat is supposed to follow redirects, in my case, it did not do it when using subdomain_fu to handle subdomains as accounts.
The response.body contained only the string “you are being redirected” which is a real bummer when you’re writing cuke steps.
My solution was to hack in a “follow_redirect! if redirect?” to a bunch of the webrat steps. This allowed me to write up my scenarios as usual. But if anyone knows why this is happening and how to fix it at a more basic level, please let me know.
Things I wish I learned in school.
I graduated with a degree in C.S. in the early nineties. The dot com bubble had yet to inflate, Intel cpus had not yet hit the gigahertz frequencies and windows 95 and OS/2 were duking it out. Well, actually OS/2 was already dead, I simply refused to believe it.
Having worked in the industry for a few years, dropping out for a stint as an entrepreneur and trying to reboot and start in programming again, I see a number of things that my extended experience and perspective give.
This post isn’t to disparage my education. One of the most valuable lessons I learned from the university I attended was how to learn. Not how to sit while being taught. But how to discover how something worked, what it meant and most importantly the process of doing this without being told how to do it. But I digress. Here’s a list of things I didn’t pick up from school but wish I had.
How to write good code
Assignments and projects were generally graded on if it worked or not. While style was a small part of the grade, I don’t recall any strong emphasis of writing good code. What is good code? I’ll refer you to Clean Code by Robert C. Martin, which should be required reading for any CS student.
How to read code
As a practicing software engineer, you’ll need to write code. But you’ll also need to read it, and you should read as much as possible. Check out Code Reading by Diomidis Spinellis.
TDD or BDD
This is one that didn’t exist (afaik) at the time I was in school. The state of the art at the time was the Carnegie Mellon Maturity Model. If they aren’t teaching TDD and/or BDD by now, it is a travesty. Earlier this year, I was searching for extension classes that covered agile methods and/or TDD and there was very little I could find. I don’t have a particular link for a book since the one that I used is still in beta and I had to fly to Michigan to learn from a guru.
Learning different languages.
The first language I learned in CS101 was Pascal. Nothing wrong with that. I just hope current students also get exposure to more than C++ or Java. Things like lisp, smalltalk, erlang or Haskell are great for expanding your mind.
These thing aren’t easily done in the short semester or worse a quarter based system, so perhaps these are best done outside of the educational environment, and picked up in practice of coding. Then the onus falls on employers who hire fresh grads to properly mentor and guide the fresh mind toward professionalism. Does anyone hire new grads anymore?
Things I am grateful to have learned:
It wasn’t all bad, or a waste of time. I learned a great many things that I would have otherwise had great difficulty picking up on my own.
- Electrical engineering and computer engineering courses. Wiring up a ripple adder and simulating circuits on a workstation was a blast. The basis of digital electronics comes in quite handy when I’m playing around with my crazy projects.
- CS basics. Algorithms, Data structures, etc.
- My general education. Engineers (and others) need to understand the underpinnings of society and the humanities. To communicate with others. To put life in context.
Finally you don’t need to go to a school to learn all these things. A person with a sharp mind, massive determination and a passion for learning is all it takes. The internet with all its free blogs, articles and videos along with a number of books can be a fine substitute for formal education if the proper choices are made. But the formal education helps guide the student and speed the process for the majority of people.
ajaxy file upload
Posted by Ed in programming, rails on September 10th, 2009
how to do ‘ajaxy’ file uploads, or file uploads that don’t reload the page.
First, there is no way to do a file upload using true ajax, or XMLHTTPRequest. You can get the same effect via flash, or what I’m using, a little trick using the target attribute on the form to post to a hidden iframe on the page. This allows you to do a standard post, without seeing the ugly request/reload cycle flash before your eyes.
What you’ll need:
- The form and iframe in the page
- The respond_to_parent plugin. This is a tiny plugin that allows you to respond to the main page, instead of the iframe.
- Controller logic to handle the request
- And for good measure using an association model to save a file using attachment_fu. I know people like using paperclip, but I like using have_many associations for my use cases.
Steps
- Create the attachment model and the db migration to hold the metadata.
- It should have a XXX_id field to the owning model. The models should have the association, has_one or has_many, as your situation demands.
- It needs the metadata required by the plugin. Common ones include: :content_type, :max_size, :resize_to, :thumbnails, :storage, and :path_prefix.
- use the has_attachment function to define the class settings for the attachment model.
- With the models and db tables setup, the next step will be the controller/views
- Generally I like using nested RESTful resources to handle creating the attachment objects. Each situation is different, making the views and workflow different for each situation.
- I also use progressive enhancement for javascript popups to do on-page file chooser dialogs, but the first step is to make sure the non-js enhanced functionality works. As a plus, this allows us to run integration tests using cucumber.
- Create the resource in routes.rb
- Testing with cucumber
- Validation issues
Of course, I didn’t do any of the original work on this. References:
- http://kpumuk.info/ruby-on-rails/in-place-file-upload-with-ruby-on-rails/
- http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent
- http://github.com/technoweenie/attachment_fu/tree/master
- http://clarkware.com/cgi/blosxom/2007/02/24
- attachment_fu_validates_attachment
dynamically adding a form to post
Posted by Ed in programming, rails on September 10th, 2009
I’ve been using UJS (Unobtrusive JavaScript) techniques lately, with prototype and lowpro. The default Rails helpers emit the following code when doing a http method put or delete, when working with restful resources:
var f = document.createElement('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
var m = document.createElement('input'); m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);
f.submit();return false;"
Definitely a code smell. I was working on a bit of code that emulates this using UJS in a way. I ended up not using this, but I’m putting this here in case I need it again or if it helps anyone. The interesting thing here is using the prototype builder to dynamically add a form to the dom once, and only once. It’s fairly straightforward, and
Event.addBehavior({
'a.attendance_event_toggle:click' : function (e){
var form;
// create the hidden form to post data
if ($('event_toggle_form') == undefined ) {
form = new Element('form', {
action : this.href,
'method' : 'POST',
'style' : 'display:none',
'id' : 'event_toggle_form'
});
var input_id = new Element('input', {
'type' : 'text',
'id' : 'cycle_user_id', 'name' : 'cycle_user_id'
});
form.insert(input_id);
$('attendance_table').insert(form);
}
form = $('event_toggle_form');
form.action = this.href;
$('cycle_user_id').value = this.readAttribute('uid');
alert($('event_toggle_form').action + " uid "+ $('cycle_user_id').value); // set the hidden form values
form.submit();
e.stop();
}
});
Yay!!! Finished latest project (laracingdragons.org)
Posted by Ed in business, programming, rails on August 24th, 2009
A celebration is in order!
We deployed the latest, spiffy website/webapp for a non-profit sports team and finally finished up this week. It’s result of learning a ton of new technologies and techniques, such as Rails and BDD. A huge part of the success of getting it out was Kenny spending his very limited time doing some crazy good CSS and design.
It came out very nicely, and actually met the twin goals of meeting the needs of the two main stakeholders.
- The general public. They need an accessible introduction to the sport in general, and what the team means to them specifically. We’ve already had a number of new members show up at practice solely based on their use of the website.
- The team members. Much of the scattered paperwork and procedures have now been centralized in the webapp section of the site. This should make life easier for the all-volunteer staff of the team, making them more effective and happier.
Of course things are never ever really finished, there are many more features on the drawing board, but the milestones for this release were hit, and we’re moving on to the next major project.