Hidden features of Perl?

The flip-flop operator is useful for skipping the first iteration when looping through the records (usually lines) returned by a file handle, without using a flag variable: while(<$fh>) { next if 1..1; # skip first record … } Run perldoc perlop and search for “flip-flop” for more information and examples.

Hidden features of C

More of a trick of the GCC compiler, but you can give branch indication hints to the compiler (common in the Linux kernel) #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) see: http://kerneltrap.org/node/4705 What I like about this is that it also adds some expressiveness to some functions. void foo(int arg) { if (unlikely(arg == 0)) { … Read more

Hidden features of Ruby

From Ruby 1.9 Proc#=== is an alias to Proc#call, which means Proc objects can be used in case statements like so: def multiple_of(factor) Proc.new{|product| product.modulo(factor).zero?} end case number when multiple_of(3) puts “Multiple of 3” when multiple_of(7) puts “Multiple of 7” end

Favorite Django Tips & Features?

I’m just going to start with a tip from myself 🙂 Use os.path.dirname() in settings.py to avoid hardcoded dirnames. Don’t hardcode path’s in your settings.py if you want to run your project in different locations. Use the following code in settings.py if your templates and static files are located within the Django project directory: # … Read more

Hidden features of HTML

Using a protocol-independent absolute path: <img src=”//domain.example/img/logo.png”/> If the browser is viewing an page in SSL through HTTPS, then it’ll request that asset with the HTTPS protocol, otherwise it’ll request it with HTTP. This prevents that awful “This Page Contains Both Secure and Non-Secure Items” error message in IE, keeping all your asset requests within … Read more

Hidden features of VBA

This trick only works in Access VBA, Excel and others won’t allow it. But you can make a Standard Module hidden from the object browser by prefixing the Module name with an underscore. The module will then only be visible if you change the object browser to show hidden objects. This trick works with Enums … Read more

Hidden Features of VB.NET?

The Exception When clause is largely unknown. Consider this: Public Sub Login(host as string, user as String, password as string, _ Optional bRetry as Boolean = False) Try ssh.Connect(host, user, password) Catch ex as TimeoutException When Not bRetry ”//Try again, but only once. Login(host, user, password, True) Catch ex as TimeoutException ”//Log exception End Try … Read more