Life as Code

refactoring my life

Archive for the ‘hack’ Category

accessing ruby I18n locale messages from the web client

leave a comment »

I like to keep my client-side code completely decoupled from the server-side but I still want to keep one message source for localization.

The ruby stack I use includes Sinatra, Sinatra::I18n and the I18n gem for localization and this is the simplest and most effective way (that I’ve found) of accomplishing this:

The Sinatra route:
get '/locales/:locale_name/messages.js' do |locale_name|
    locale = locale_name.to_sym
     
    if I18n.available_locales.include? locale then
        messages = I18n.backend.send(:translations)
        "var m = " + messages[locale].to_json 
                    + "; t = function(k){ return eval('m.' + k); }";
    else
        not_found
    end
end 

This way the yml locale file is loaded and served and wrapped for quick use.

In the client just request the messages script and then when you need a message call t(‘message key’) just like you’d do it in ruby :)


var message = t('message.key');

Written by Bogdan

August 30, 2014 at 9:29 PM

Fastest web stack you could possibly set up for prototyping

leave a comment »

You should be already used to my religious prototyping habits – I tend to try out a lot of stuff, build a lot of things that I later discard and so on.

Knowing that I do this a lot, I tend to actively look for tools that are either very easy to set up or that don’t even have an install footprint. Last year (I think) I found Mongoose, and used it to replace my normal prototyping instance – an Apache instance that I had running all the time on my dev machine.

Mongoose turned out to be the best choice, being just an executable (small – in the hundreds of kilo range) that you can run to get an instant web server, serving files from any folder.

My normal usage is to copy the Mongoose binary and a small config file to an empty folder and then to start churning out HTML, CSS and JavaScript – and it worked fabulous… until I needed something dynamic and I was forced to switch back to Apache.

Well, tonight I got my revenge. I needed some dynamic calls to test a RESTful API, and because my API builder is not ready yet I had to resort to some fast PHP hacking.

As my new home dev machine is not fully configured yet and I had no Apache installed and configured I thought what the hell, how’s about trying to hook up the Mongoose CGI. I knew it had support for it but I never tried it before, until now.

So, without further a due, I present the fastest setup for a prototyping web stack (on Windows) ever:

1. Create a folder – duh

2. Get the latest Mongoose binary from http://code.google.com/p/mongoose/downloads/list and copy it to the folder

3. Get the latest PHP zip distribution from http://windows.php.net/download/, unzip it and copy the php support files for CGI to the folder (php-cgi.exe, php5.dll and php.ini are enough)

4. Create a mongoose.conf file with the following lines:

listening_ports 80
document_root .
cgi_pattern **.php$
cgi_interpreter .\php-cgi.exe

5. Run the Mongoose binary (I usually rename mine to mng.exe) and access it with your favorite browser

And that’s it, you now have a web server and PHP configured, all under 5 minutes. Enjoy!

You should only use this for prototyping stuff – NOT FOR ANYTHING SERIOUS LIKE A PRODUCTION OR CLIENT-ACCESSIBLE INSTANCE!

Written by Bogdan

September 27, 2012 at 11:11 PM

Stop Visual Studio Express 2012 from SCREAMING at you

with one comment

I don’t develop .NET code professionally but I do like to keep my tools sharp in every direction – that includes knowing the latest technologies even if they don’t relate to JEE.

Playing around with .NET means I need a good environment at a reasonable price (read free) and after trying SharpDevelop and VS Express a couple of years ago I decided that the best IDE for me was VS C# Express.

After happily using it for more than 2 years I upgraded to VS Express 2012 for Windows Desktop (there’s no C# edition anymore) and surprise – the menus WERE SCREAMING AT ME IN ALL CAPS.

At first you ignore it but after a while it becomes really annoying so I decided to fix it.

I asked around and I found a post by @shanselman that mentioned a registry trick to stop VS from capitalizing menus but it only worked for a full install of Visual Studio and not for Express.

I fired up my trustworthy procmon, identified the registry path for VS Express, tried it and it worked. Here’s how it looks like:

Image

If you want to fix it too, here’s the registry key and value that you need to create:

HKEY_CURRENT_USER\Software\Microsoft\WDExpress\11.0\General

SuppressUppercaseConversion

DWORD value of 1

Written by Bogdan

September 19, 2012 at 10:02 PM

Posted in .NET, Development, hack

Tagged with

Writing it down is good, doing it is better

with 2 comments

Either you run the day or the day runs you.

Jim Rohn

I always try to sell the “write down everything that you need to do” mantra to everybody.

It’s not just because it works for me, it’s because it works for everybody I ever worked with, everybody I asked and just about every productivity book I ever read mentioned it.

The mantra is very simple:

  • I use a piece of paper (usually a page in my notebook – paper notebook smart-ass) to create a list of things TODO
  • If I get a new task, I write it down
  • If during my work I realize that there is something else that I must do to accomplish the task, I write it down
  • If during my work I think about something that must be done later on and hope that I don’t forget, I write it down
  • When I do it, I scratch it off the list as being – you guessed it – DONE

You might be thinking “this douche is trying to sell us the TODO list crap” – and you’re right, that’s what I’m doing.

You would be amazed at the number of people who are actually trying to remember (with their actual meaty mushy forgetful minds ) the things that they need to do during an entire day – even an entire week, so the list thing… well, let’s say that it needs a good refresh from time to time.

You would also be amazed at how much a piece of paper and a pen used – religiously – as a TODO list and actually followed on a daily basis could increase your productivity. You should try it. Screw Outlook reminders and other RememberTheMilk simulacrum – try using a real piece of paper and a pen, and really scratch the hell out of a task when you’re done. You’ll feel a lot better.

Although this seems to be the direct that this post is heading, it’s not about using TODO lists, nor even about prioritizing them (although it would be a good subject) – it’s more about knowing when not to use them.

Let’s say that you’ve been using TODO lists for a while now. It’s really working for you. You’re burning two A4 sheets a day with your tasks, passing the unfinished tasks on a new list each morning. Handling it, feeling the DONE thrill every time you scratch something off.

Then you start to notice something. Some really simple, really small tasks seem to remain on your list for more than one day, maybe two, maybe even a week. And when you finally get to them you realize that those tasks were under 10 minute tasks. Some of them were even important, or could have brought a benefit, or even a favor. So this is what this post is about.

It happened to me awhile ago (a couple of years to be exact – and yes, this is a revived draft, I tend to do this often lately) so I made this little habit of asking a few questions before writing it down:

Will it take more than 5 minutes?

If it will take more than 5 minutes – write it down. If it’s faster than that just do it – and save Mother Earth.

Are you doing something so important that if you deviate for 5 minutes it will be context switching?

If it will throw you off, write it down and do it later.

Can you do it in the middle of the current task, as a short mental break?

From time to time I need to clear my head of whatever nasty thing I’m working on and I found that (besides taking a walk around the office building) handling a short unrelated task clears my mind.

Can you delegate it?

If it can be delegated – write it down – and email it. Maybe have a quick chat about it.

Do you really need to do it? 

Think about this: maybe you don’t really have to do it. Is it really necessary?

I hope this helps you as much as it helps me.

Written by Bogdan

April 3, 2012 at 12:45 AM

Follow

Get every new post delivered to your Inbox.

Join 264 other followers