Little terminal trick

If you have to delete a folder which contains locked files, the Mac OS X Finder won’t let you (because the “locked” flag is used precisely for that!). If you want to remove such folder (typically folders coming from a Subversion checkout have this problem) run these commands:


sudo chflags -R nouchg to_destroy/
sudo rm -r to_destroy/

Where “to_destroy” is the name of the folder that you want to get rid of. As always, be careful! There is no confirmation dialog whatsoever! You’ve been warned.

How to make in X11 so that the focused window follows the mouse?

Another long title.

Just a quick one, not to forget: in Apple’s X11, if you want to have the focus follow the current window, just type the following at the terminal window:

defaults write com.apple.x11 wm_ffm -bool true

Restart X11 and that’s it! This is particularly useful in apps like Gimpshop that have several open windows simultaneously (for the palettes, the layers, and the images themselves).

How to test software security?

Howard and LeBlanc give a very complete answer to this question in their classic “Writing Secure Code” book:

Most testing is about proving that some feature works as specified in the functional specifications. If the feature deviates from its specification, a bug is filed, the bug is usually fixed, and the updated feature is retested. Testing security is often about checking that some feature appears to fail. What I mean is this: security testing involves demonstrating that the tester cannot spoof another user’s identity, that the tester cannot tamper with data, that enough evidence is collected to help mitigate repudiation issues, that the tester cannot view data he should not have access to, that the tester cannot deny service to other users, and that the tester cannot gain more privileges through malicious use of the product. As you can see, most security testing is about proving that defensive mechanisms work correctly, rather than proving that feature functionality works. In fact, part of security testing is to make the application being tested perform more tasks than it was designed to do. Think about it: code has a security flaw when it fulfills the attacker’s request, and no application should carry out an attacker’s bidding.

(Howard & LeBlanc, 2003, page 568). Continue reading

JavaScript tips and tricks (4)

For the last article of this series, I’ll let Douglas Crockford do the talk :) This is an amazing video about the good and the bad parts of JavaScript, as seen by a guy that seriously, seriously knows his stuff: Douglas works in the YUI team at Yahoo!, and has written a lot about JavaScript: he coined the phrase about JavaScript being the world’s most misunderstood language, and wrote the amazing JSLint tool.

I the video below, Douglas exposes all his thoughts about the language, both the good and the evil, all out of his own experience as a guy who had to rediscover JavaScript in 2000. Really interesting stuff!

JavaScript tips and tricks (3)

How to organize code in “namespaces”

When you use lots of libraries in your code, you can easily pick up a function name that corresponds to a pre-existing name in some library that you might have included. To avoid that, you should create namespaces that encapsulate the code of your application:

[source:javascript] var net = { kosmaczewski: { adrian: { blog: { articles: {}, images: {}, snippents: {}, tutorials: {}, rants: {} } } } };

// Shortcut (for performance purposes) var blog = net.kosmaczewski.adrian.blog; [/source] Continue reading

JavaScript tips and tricks (2)

Object-Oriented Programming in JavaScript

Functions are also used to represent classes when doing object-oriented JavaScript. There are several possible ways to write object-oriented JavaScript code, but they all turn around the concept of the “Function” class:

[source:javascript] function Thing() { var privateField = “PRIVATE”; var self = this; // See below for more explanations about “this” :)

var privateMethod = function() {
    alert('Private methods can be called from public methods');
    self.anotherPublicMethod();
}
this.publicField = "PUBLIC";
this.publicMethod = function() {
    privateMethod();
    alert('From the public method;\nthis is a public value: ' + this.publicField +
    '\nand this is a private value: ' + privateField);
};
this.anotherPublicMethod = function() {
    alert('You need a trick to call this from a private method!');
};

}

// Creating a new instance of “Thing” var thingy = new Thing(); thingy.publicMethod(); // you can also call thingy“publicMethod”; [/source] Continue reading

JavaScript tips and tricks (1)

JavaScript As I said yesterday, JavaScript is the world’s most misunderstood language, which means that you must unlearn what you have learned. However complicated it might seem at first, it is quite easy to write and understand the most complex of JavaScript codes with just some examples.

Just a few observations before starting:

  • Semicolons (;) are not mandatory, but strongly recommended!
  • You can create strings using either ‘apostrophes’ or “quotes”. “You can also ‘mix them’ as you want”, but ‘always keeping the “order” when using them’.
  • Always use the “var” keyword when defining variables. Otherwise, the variables will be created on the “Global Object” of JavaScript, and this is a bad thing(TM): variables created in the “Global Object” do not get garbage collected!

Continue reading

How to export “shared” Google Reader items?

If you are an avid Google Reader user (like me) you must be surely be “sharing” items that you read, for you or for your audience; in my case, you can see my recent “shared items” in the sidebar at the right side of this screen.

But can you export these shared items to a file? Google Reader does not allow you to do that from the interface, but you can use the URL below to do that. Just replace {USER_ID_HERE} by the ID of your user ID (it might require your Google authentication), and you’ll get the last 10’000 items that you shared in the form of a long Atom XML file, that you can download and store.

[source:php] http://www.google.com/reader/atom/feed/http://www.google.com/reader/public/atom/user/{USER_ID_HERE}/state/com.google/broadcast?r=n&n=10000 [/source]

Update, 2009-11-06: The URL has changed (thanks to Jordan Peacock for the heads-up!); try this URL instead now:

[source:php] http://www.google.com/reader/public/atom/user%2F{USER_ID_HERE}%2Fstate%2Fcom.google%2Fbroadcast?r=n&n=100000 [/source]

Update, 2009-11-06: Check out this project on Github, which has a set of scripts to help you download your shared items to HTML pages in your own computer for later reference.