7nbsp

quick tech tips and helpful codebits

json: The importance of spelling gud

by Ryan on May 10, 2012

All over the web in programming forums, tutorial sites, and instructions on related things, you’ll hear all about this famous guy that everyone knows. Some dude named json. First off, why this jerk won’t let anyone spell his name with a capital j, like you are supposed to, is beyond me. Already I don’t like him. And why should I send him anything? All the APIs think he’s the best guy in the world. It makes me wonder why json, or Json (corrected) isn’t the svelte guy in the Dos Equis commercials, the way everyone talks about him. He’s not that special. And another thing, he wants to be all new-fangled web 2.0 and not add the “a” to his name like everyone else. See, I told you he’s a punk.

…[somehow stumbles on the fount of all wisdom and flawless knowledge, Wikipedia and ends up on the json page. Face turns red. Embarrassed-o-meter pegs 1o. Tries to backpedal.]

So, I guess that JSON guy is, well, alright after all. I didn’t know he was cool, but now I get it. Apparently his name is fine without the “a” and should be all caps (if that is his real name). Also, he isn’t a guy at all. Well, this has been a very revealing day. Now I get it. I guess, as with programming, you have to spell things correctly, and also not assume things are spelled wrong. JSON is an acronym, not a person’s name. Though I could see newbs being confused by that one. It is the strange leap of logic and conceptualized ideas that throws people for a loop. More of us programmer types need to help people understand more and level them up instead of ignoring their “dumb” problems. Solution to dumbness => provide ways to become smart.

Cross-posted on Myrth.net (where everyone — programmers included — has more fun).

Rails: Use sandbox option to test without changing the database

by Ryan on May 7, 2012

If you are new to Rails, you may not know that a simple option when using the rails console is all it takes to avoid permanent database changes while you are learning or testing a bit of your app.

In terminal (or Command on Windows) you would normally write:

To enable sandbox mode (which rolls back any database changes when you exit) simply write this:

It is all in the the command line switches. And all in the wrist. Happy consoling!

Rails: Render Partials

by Ryan on May 7, 2012

I’ve been working on completing Michael Hartl’s killer — and free — rails 3.2 tutorial for a while now. When I learn new concepts I have to write them down so I won’t forget and will have a reference to go back to, if I do. This is one of those posts.

To have elements of your web page appear without having to rewrite the same code in each page, web developers (like me) use includes of some kind to insert common bits of code once and it gets dynamically generated by the server. In rails, this is called a partial. You can put things like a footer with links, a header with nav, or other elements in partials and then include them in your main layout to display that code automatically.

You would create a new file in the app/views/layouts folder and name it with an underscore at the beginning. Like zoy:

_footer.html.erb

and then put your footer html in it. Then all you do is add this to your main application layout:

It is that simple. Yay rails!

Javascript: Sleep timer

by Ryan on May 3, 2012

In javascript, there is no such thing as a sleep timer. This is not a nocturnal alarm clock, but a programming function that will stop the code from running for the time set in it. Since javascript doesn’t provide this you have to use setTimeout or this method to create a sleep timer.

This code was written by Marcel of http://www.nodebeginner.org/ He’s a smart guy and I recommend you buy his book on node if you want some great info on node (not to mention the excellent tutorial on the same site. Here is the code:

Cardinal Rules: Provide value, not frustration, then I’ll subscribe. Maybe.

by Ryan on May 3, 2012

Many companies who now have a website because their customers have forced them into it — kicking and screaming — get this one wrong.

Traditional media companies are the worst. They assume and expect you to pay for their lovely wonderful content BEFORE you even get to evaluate and see what it is you’re paying for. Once upon a time, you could go to a store or a newsstand and page through the latest magazine, “Cat & Demon” for example. You could get a general sense of what the magazine was about, does it peak your interest or fail to entice? You bought it based on that feeling of interest, or left it there because it didn’t grab you. For some reason this does not in many case translate to the web. Magazine websites tend to show you nothing or very little before they require you to register (even if it is for free) before you even get to see any content. A dirty little trick they use is to work their search results hard with clever titles like “35 ways to blah blah blah happy lucky gorgeous whatever” and as soon as you click it, they show you the first of 13 images, in a gallery format. As soon as you click the next image, it doesn’t give you what you expect or deserve, as 100 better sites would do, and let you see the image as promised. It instead takes you to a registration page.

If you do this on your site, I don’t care what it was I wanted to see. I will leave that instant and never be back, never. I will remember. There is no reason to entice and then frustrate your users just because you think I should subscribe and let you send me emails just for the privilege of seeing your content (which most likely is crap and not worth looking at). I won’t know until I see it.

Here is a foundational business principle. Provide value, THEN ask me to subscribe to keep it coming. There is no reason I would sign-up for more email unless I know that you will provide what I want in it. I don’t trust you until you earn it. Don’t be stupid.

SQL: Easy Database Sync with SQL Delta

by Ryan on May 1, 2012

If you’ve ever worked with SQL Server or another database system, you’ve likely run into a situation where you need a way to sync changes from one database to another. If you develop with databases, you may want to do things like sync a dev database to a production database, and the ability to sync only certain objects and data could be very valuable, allowing you to selectively update parts of a database. I have looked at a lot of tools to help accomplish this, and there really aren’y many that are free especially, and few that perform this task well.

A tool that I just started using and have already fallen in love with is SQL Delta. It has a friendly, simple interface (which is weird in the IT world) that gets the job done with style, and makes things too easy to do. It is helpful, descriptive so there is little confusion, and has a bunch of tools that make the process cake.

You sign in to both databases from Delta, it compares everything (structure and data, though on different tabs) and tells you what differences there are between servers. It is literally the first-cousin of subversion or Visual Source Safe’s Diff tools, but it makes way more sense than that. I was able to sync 2 databases in minutes and it saved a project I was working on a lot of time and agony.

The single user license for Delta is $330 at present, which is nothing compared to the value it provides. They offer a 14 day trial — where everything seems to work as it would when purchased — as opposed to the trials that are “full featured” and only let you sync 4 records to “try it out” (ludicrously inadequate). They also have an Oracle version as well, which I haven’t tried but expect is just as good as the SQL version. This is for Windows only, but since you need windows to use SQL Server, it makes sense. If you’re looking for a database management tool to diff and sync all that juicy yummy data, consider this tool. It is a keeper.

SQL Delta

MOBILE: Don’t make me wait

by Ryan on May 1, 2012

When designing a mobile app, it is important to make sure you save your users as much time as possible. Google’s Android Market app, now called “Play” (which is a stupid name for it BTW) is a bad example of what not to do. Many other apps do it too, including the Apple App Store.

So, let’s say I searched for something on my iPhone or Android, I wanted to find a tower defense game I heard about online. I search for it and look through the options. Whether I find one I like or not, less than a minute later, I am done with that search. I either find what I want and download it, or I don’t and abandon the idea for now. Why then should I be assaulted by the same search the next time I visit the store, when my search will always be something new? I want the mobile apps to act just like Google’s homepage. It gives me a blank search box to type in what I am looking for now. It doesn’t bother with what I wanted last time.

This isn’t such a huge issue normally, but it starts to really frustrate me when it takes a while to load all the images and other assets from the last thing I looked at, and I have to wait for a while (especially with spotty wifi or 4g coverage) to get around to being able to search. Apps should never block me from searching or having to wait to get to what I want. There should be a feature in these “app stores” to ask me (unobtrusively) if I would like to load the last search again, or if I just want to search, I can without any stopping to wait for something I no longer care about. It happens 100 times a day and it is super annoying. What I am asking for is the ability to discard the continuity of my last search over sessions, when I would rarely ever care more than once. If I do, I will search for it again, and use the autocomplete features to re-search. Please don’t block me from my new obsession of the moment.

What would be great is if I could at least interrupt the  loading of crap I don’t want to see with an etch-a-sketch like shaking motion or something equally fun. Still, just because this is mobile and we haven’t worked out all the kinks, doesn’t mean you should allow this annoying behavior happen.