How to use resizeTo in Safari (if it doesn’t work)

Many people are probably familiar with the fact that most browsers allow Javascript code to be entered in the address field. That’s the magic behind bookmarklets, which simply spare the user the hassle of manually typing long, convoluted and obfuscated Javascript statements.

While it’s usually pointless to do so, there is one case in which it makes perfect sense: resizing the browser window to an arbitrary size, in order to test what a website looks like. Essentially, by setting the browser window to a size such as 1024 x 768, one can have a relatively reliable idea of what the current website would look at that screen resolution. In truth, one would have to take the graphical elements of the operating system in question, but it’s usually a fine way to get an idea.

The code to do so is very simple:
window.resizeTo(width, height);

Therefore, if we want to set the window to 1024 x 768 pixels, we type the following pseudo-address:
javascript:window.resizeTo(1024, 768);

and press enter. A few things worth noting:

  • Capitalization is important. It is resizeTo, with a lowercase “r” and a capital “T”
  • There is no space, nor any slash, after the colon
  • The width and height have to be separated with a comma, and (of course) have to be integers
  • The semicolon at the end is optional, but if you’re a programmer it will be natural to type it
  • In some browsers, you can omit the “window.” part, as the current window is implied

This is all good and great, and works in most browser.

Safari, however, only allows this intermittently. Since I spent some time making tests to figure it out, here is a tip: Safari will execute resizeTo only when there is one (and only one) tab in the window.

I’m not sure whether this is caused by a specific setting on my machines, or if it’s a default, or if it can be even changed, but I can see the point in this behavior. Since some websites have the bad habit of resizing the current window to full screen (an annoying and pointless habit, if you ask me), Safari blocks the execution of such command in order not to disrupt the concurrent navigation of different websites/pages.

It’s as if it said: “if this is your own window, do what you want with it; if not, you’ll have to respect your tab brothers.”

So, if resizeTo isn’t working for you, drag that tab out of the bar so it’s instantly opened in its own window, and try again.

Languages: the strange case of Pirahã and Aymara

In my last post, I wrote about the connections between language and thought, ie. linguistic relativity / determinism.

In today’s highly globalized world, languages get mixed and evolve at a much faster pace than ever before. English, for instance, is no longer only divided into British, American, Canadian and Australian English; we could say that there is a variety or dialect of English for any other natural language: Spanglish, Chinglish and so on. When French was the de-facto lingua franca of diplomacy (and, by extension, Western Europe), it was not substantially modified by other local languages; yet when English replaced it, after World War I and especially after World War II, it started changing immediately.

English, in particular its American variety, was not only originally used for international diplomacy; rather, as the United States rose a superpower in many fields (technology, business, etc.), one could argue that its language became widespread from the bottom. The average Joe in most other Western countries was exposed to American words: they wore blue jeans, they put coins into juke-boxes, they went to a bar. English words became commonplace over time, and this ultimately led to the creation of what could be easily considered a series of creoles that are, for the most part, mutually intelligible.

Continue reading “Languages: the strange case of Pirahã and Aymara”

Languages: linguistic relativity, words vs. thought

One of the most intriguing concepts in linguistics is the so-called Sapir-Whorf hypothesis, or linguistic relativity principle. Simply put, it states that the language we speak can influence the way we think. Another common name for this theory is linguistic determinism. There are some subtleties in the usage of these different names (no pun intended), but in order to avoid confusing them and giving wrong information, I’ll refrain from attempting. There are many resources online about the details of this topic for those who wish to delve deeper. For the sake of this post, I will freely use the terms interchangeably.

Anybody who studied a foreign language, even without reaching fluency, has most likely had an experience with the linguistic relativity principle. The farther the language in question is different from the native language, the more the phenomenon is obvious.

Continue reading “Languages: linguistic relativity, words vs. thought”

Manual duplex printing on a laser printer

My laser printer, a Samsung CLX-3175, does not have any tool for automatic duplex printing. Achieving such result manually is not difficult, but may take some trial and error in order to get the settings right. That’s exactly what I’ve done, and I’m writing this post as a note to myself. Should it be useful to anybody else, however, by all means let me know with a comment.

Keep in mind that this is for my own printer, and that I use OS X 10.6 “Snow Leopard.” Results may vary with different printers and/or operating systems, so make your own tests. If your printer outputs pages “face down,” this will probably work as it is. Most ink-jet printers on the other hand output prints “face up,” so some adjustments will be necessary.

In any case the steps for my own printer are very, very easy (once you’ve figured them out correctly):

  1. Print all odd pages in normal order
  2. If the total number of pages is an odd number, take the last sheet and put it away for the time being
  3. Take the (remaining) sheets and put them back into the tray after rotating them 180°. Do not flip them in any way!
  4. Print all even pages in reverse order
  5. If you put the last sheet away in step 2, put it back at the end of the stack
  6. There is no step 6

Enjoy. 🙂

TV shows I’ll be watching

In case anybody cares, here is what I will be watching:

  • Weeds (season 6), Showtime, Mondays — in progress
  • Cougar Town (season 2), ABC, Wednesdays — starting Sept. 22nd
  • The Big Bang Theory (season 4), CBS, Thursdays — starting Sept. 23rd
  • 30 Rock (season 5), NBC, Thursdays — starting Sept. 23rd

Of course, if you — like me — don’t live in the US, there are ways to watch them almost live. You could start looking at the sidebar of this blog, for instance.

Why am I saying this? Well, I may write about the shows here as I have done in the past, so be warned.

Incidentally, you may notice that they’re all sitcoms, aside from Weeds which is somewhat difficult to classify, but definitely has quite some humor. That’s because the days are getting shorter, the weather is getting worse and S.A.D. is lurking in ambush behind the corner. By the way, do those Philips LivingColors thingies help at all?

Prettifying URLs with fake subdirectories using mod_rewrite

Lately, I have been trying to define a common basis for most of my web projects, since I often end up reinventing the wheel every time. I have tried a few PHP frameworks, but none of them tickled my fancy, but I have complicated tastes. I am known for reimplementing something from scratch rather than wasting time adapting other people’s code to my needs, and it’s often much faster too.

Therefore I have been working on JBFW, my very own PHP/Javascript framework. One of the key components of it is pretty URLS and a centralized index.php to handle most of the things.

If you access http://mysite.com/news?lang=en, the server will transparently route that to http://mysite.com/index.php?pagename=news&lang=en. At that point, index.php runs the news module if it’s present, and then loads the news template (possibly showing the result of what was done in the module, if it was called at all.) I find that it’s a very slick and modular way of handling things, as static pages only need new templates and boom, they are live, with the rest of the framework readily accessible.

The mod_rewrite configuration for such a behavior is as follows:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?pagename=$1&%{QUERY_STRING}

This means: if the requested filename is not a directory and is not a file, route the request as described (knowing something about regular expressions, or being proficient in creative swearing — which goes hand in hand with regexp — comes in very handy at this point.)

I used a similar, but coarser, approach on my own main website, http://www.nicolucci.eu. There, I even used fake subdirectories, so that http://www.nicolucci.eu/photography/book/glimpses will have it show the photography-book-glimpses template. Neat, but doesn’t work with real subdirectories. It’s not a big problem on that site, but when you need to have a separate administration section, you need real subdirectories. The problem is that, using the approach I described above, http://mysite.com/admin/login into http://mysite.com/index.php?pagename=admin/login, and while the correct function could be run in PHP by mangling the request as it’s done for the “top level” modules, it could quickly turn into a nightmare.

The solution is to add another set of mod_rewrite rules, as follows:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((.*)/)+(.*)$ /$2/index.php?pagename=$3&%{QUERY_STRING} [L]

Yes, that’s incredibly messy, and I’m pretty sure that there is a better way to do it. However it works, and for now I’m going to concentrate on finishing the website and go back to it later. What this does is: if the request has one or more blocks ending wish a slash (the directory), followed by something else (the file name), it is routed to index.php inside that directory, using the file name as a parameter to pagename, plus the original query string as usual. The [L] at the end tells mod_rewrite: please refrain from doing any other change, this is flaky enough. This ensures that http://mysite.com/admin/login effectively calls http://mysite.com/admin/index.php?pagename=login.

Note that this is another block of RewriteCond and RewriteRule, and goes before the original one. I tried to put them together, since the conditions are the same, but after fifteen minutes of trying all combinations I gave up. I’m sure I was one attempt away from getting it right.

A very clever thing (ok I’m kidding, it’s a side effect I hadn’t fully realized but I’m glad it’s there) is that addresses such as img/logo.png are not rewritten because those files do exist. It would probably make sense to exclude common file extensions, such as image files and javascript, from this kind of mangling; or even better, make it only work when the “file name” part does not have a dot in it. I’ll find a way to do it, at some point.

To finish up, an extra little trick that can come in very handy when you want to make sure that certain files are not downloadable by anybody:

<Files ~ "\.sqlite3$">
Order Allow,Deny
Deny From All
</Files>

Make sure that there are no spaces on either side of the comma in the first line. I was quite frustrated because I kept getting the infamous error 500, and there it was.

I hope this spares someone from wasting as much time as I did with this kind of thing!

20 tips to run a business without committing suicide

Starting earlier this year, I have been a “professional” IT consultant (libero professionista in Italian.)

In practice I mostly deal with web development and computer repairs. It’s what I’ve been doing for over a decade now, since I was still in school, only now I get to pay my own taxes (yay) and therefore I get angrier when people try to rip me off. So, here’s a collection of tips about running a business I put together based on my experience. Note that I refer to the client as a “he,” but that’s just for simplicity.

  1. Befriend a lawyer. You will need one sooner or later. Most likely sooner.
  2. Assume the client doesn’t have any clue on the details of your job. Listen to his ideas, make a mental note of how you’ll approach the problem in practice, and be ready to explain to him why his “perfect” solution just doesn’t work and needs to be achieved differently.
  3. Use lots of metaphors to explain to the client why you’re doing what you’re doing, and why you’re not doing what he thinks you should be doing. Cars and houses are what people understand the most.
  4. Always require an advance payment to start a job and always require the settlement to deliver it. This protects the client from an unfinished work, and protects you from an unpaid work: if the client doesn’t settle, he loses the advance and doesn’t get the job delivered.
  5. Approved and signed quotes are fine for small jobs, but for anything more complex, a full written contract is best. Be shielded from requests that were never discussed in the first place.
  6. Don’t be afraid of writing long contracts. Rather, make sure you cover everything in clear terms. And use a big font. Contracts in small fonts are scary to most people.
  7. Assume all clients are going to try and rip you off: give little trust to strangers, trust friends even less, and just avoid relatives altogether.
  8. If a client asks for a discount, especially if it’s the first time they come to you, deny it and remind them that discounts are a (rare) privilege, not a right.
  9. Do not give discounts on the first job upon the promise that a client will come back to you, because they most likely won’t. Rather, have him pay full price on the first job and promise a discount on the next one.
  10. If some problem arises during the execution of the job, let the client know immediately, even if it’s something trivial. They will appreciate the openness and it’s a good long-term marketing strategy. By the same token, give the client as many details about the work as he needs, but no more. Too much information yields the opposite effect and confuses him.
  11. Do not plan your financial life around prospective clients. Until a quote or a contract is signed, there is no client.
  12. Realize that most clients do not check e-mail regularly or that they are unable to use it properly. You will be in touch with your clients over the telephone.
  13. Take note of the timeline of a job, ie. how long the client takes to do his part (send you materials, issue the payments, etc.) This will let you profile the client so that you can subsequently offer discounts or raise the price accordingly.
  14. Set a base price for the job, and always give a higher quote. Even if the client accepts it as it is, it leaves you room to reduce it and make a good impression on him. Again, this is good long-term marketing strategy. Moreover, learning the fine art of haggling allows you to anticipate your client’s moves and counter them.
  15. If your area has geographical stereotypes about work ethics, be prepared to see them reversed.
  16. Round prices so that they are more client-friendly when including tax, but always think before-tax for your own planning.
  17. Use legalese only when things get rough and you are getting ready to call your lawyer into the game.
  18. If possible, send printed invoices by mail after signing them. This is often pointless, but gives you the chance to add a bunch of business cards that your client can give around if they’re satisfied.
  19. Use a secondary phone number for work and give it around whenever you have the chance.  The more people have it, the more potential clients have it. And you can always turn it off if you need a break.
  20. Accept the fact that dealing with clients is like going to war. It’s bloody, messy, time-consuming, frustrating, psychologically impairing and even when you win, you wonder whether it wouldn’t have been a better idea to buy some land and grow carrots and potatoes instead. And in most cases, it would have been a great idea indeed.

Cougar Town, a lighthearted sitcom worth watching

Cougar Town is an ABC sitcom focusing on the life of Jules Cobbs, a recently-divorced 41-year-old woman (played by Courteney Cox) who struggles to find a new partner and ultimately her place in the world, as most men her age are either married or going after younger girls.

The name of show is obviously a reference to the slang word “cougar,” which refers to an older woman who pursues younger men (see Wikipedia), and to the football team mascot of the local high school. However, do not expect to see a woman chase young man after young man, because — despite what the first few episodes might suggest — that’s not how the story unfolds at all. Indeed, the first season explores the life of a group of 40-something friends (both married and divorced), and that of Jules’ son.

The writers chose a lighthearted approach to all the topics touched by the show, and that’s probably why it works. There isn’t much room for deep, philosophical conversations between any characters, and their “life-changing revelations” are fast-paced and often quite dull. One might wonder whether the characters themselves are that superficial, or if they deliberately choose not to seek important changes in their lives, settling for the path of least effort.

Still, as I said, the whole thing works. Keep in mind that this is not a show you’re going to watch if you’re looking for intricate storylines or subtle details that only come up when you play the episode again. You still find yourself looking forward to what’s happening next, no doubt, but it’s more out of curiosity than anything else. In other words, you will likely not “root” for any characters; except maybe Andy, as the guy is so clumsy and resigned that you can’t help but wish that he finally gets his way sooner or later. In any case the acting is not bad at all, and the two other female characters’ approach to life, Ellie (Christa Miller) and Laurie (Busy Phillips) do change quite a lot over the course of the show.

An interesting thing I noticed is that, while sex is inevitably a common topic and you will get clear visual clues that a couple just made love (that is, cuddling in bed under the sheets), there isn’t any nudity at all. However, even with the lighthearted approach, I suspect that a kid — and maybe even a young teenager — would fail to grasp many of the implications of divorce, age disparity and so on.

This leads me to the only complaint I have about the series: the liberal use and promotion of alcohol, specifically wine, by virtually all the characters except Travis, the son. One episode actually pivots about Jules’ attempt to stop drinking, resulting in an unusual intervention by anybody else to urge her to start drinking again. While, as I said, Cougar Town is certainly not targeted at kids or teenagers, I am surprised that such glorification of alcoholic beverages made it through. Let’s not forget that we live in an era in which there have been attempts to rate movies as “R” simply because someone smokes in them.

The episodes are quite short, barely touching 22 minutes each. If you have access to the box set or to the video files, that means that the whole first season will take less than nine hours to go through.

All in all, Cougar Town is a nice show to watch and every episode is packed with comic moments and funny quotes that will not fail to entertain. Here are a few clips to give you an idea:

httpvh://www.youtube.com/watch?v=RcsfHPMtTVU

httpvh://www.youtube.com/watch?v=xEpicBA-GEQ

httpvh://www.youtube.com/watch?v=UwmKSv1MHt4

httpvh://www.youtube.com/watch?v=71WT7ACwzew

httpvh://www.youtube.com/watch?v=mHRgMGWypvk

httpvh://www.youtube.com/watch?v=KN6rqqi1AWo

And if you manage to watch season 1 quickly, you’ll be pleased to know that season 2 premieres on September 22nd.

Dream Theater’s responses to Portnoy’s departure

A few hours after Mike Portnoy left the band, the other members of Dream Theater have started to comment on the issue.

James LaBrie wrote on his website’s forum:

Hi Everyone,

Thought I would give you time to digest the news of Mike’s departure. MIke stated that he was burnt out with the DT world and needed a break. We have to respect where he is at and where this will lead him at this particular point in time. With that being said, we are more than pumped to continue the legacy of DT and jump full on into the next chapter. Rest assured it will be great. You can count on it.

On another positive note. Matt and I are psyched with the reaction and reviews ‘Static Impulse is receiving around the world. We can’t wait until everyone can get their hands on the complete disc. and hear it the way it was intended.

I will be around more often to see how you’re all doing and to fill you with any and all news. Take care and not long now until the 27th or 28th depending on where you live.

Kick it up a notch,

James.

John Petrucci wrote on his website’s forum:

Obviously you’ve all heard the news of Mike’s departure from Dream Theater by now.
I felt it important to open up a line of communication in an effort to kill any rumors and to promote clarity.
I love Mike and really hope he’s happy and successful in whatever he does.
I realize that Mike was always the one to actively stay in touch with our fans, and I just wanted to let you know that I’m going to try to be at least a bit more present on both mine and DT’s websites and to let you all know that I am here.
To me, Dream Theater’s story is one of defying the odds, standing for true integrity in music and creating our own success through perseverance and hard work, so although Mike’s leaving is heartbreaking, I still look forward to an amazing musical journey that continues on with some of the most talented and respected musicians and composers on the planet!
-JP

Jordan Rudess opted instead to post a video on YouTube, saying:

Everyone is asking me to comment on my thoughts about Mike Portnoy leaving Dream Theater and this huge change that has happened in all of our lives. I have always been able to express my feelings and do my best “talking” through music, so I decided to voice my statement in this improvisation. Hope you “understand”

Here is the video:

httpvh://www.youtube.com/watch?v=cgqm8g95wwI

I posted this comment to it (it’s already on page 3 as I’m writing this, but it will fall deeper and deeper as time goes by):

Something must have happened. Jordan was remembering the good times, but the “ticking” at the ending followed by the angry final chord gives me the impression that there was a lot of tension building up and that the departure was not as peaceful as the press releases claim it to be.

Incidentally, I sense a bit of “it’s their fault, they didn’t respect me after all I do for the band” vibe in MP’s post.

DT is not MP. DT included MP, but doesn’t strictly need him. The Spirit carries on.

I couldn’t find any note by John Myung — he doesn’t even seem to have an official website —but I’m pretty sure that nobody is surprised about that. 🙂