Posted in Server things

Slow Putty? Prevent reverse DNS lookups

Hint from securebadshah on superuser.com here

Probably the reverse DNS resolution (server trying to get client’s name given IP) is taking time. Can you check if /etc/ssh/sshd_config has setting “VerifyReverseMapping yes” ? Set it to “VerifyReverseMapping no” and check if helps.

Edit: It seems VerifyReverseMapping is now deprecated and useDNS is the new configuration in the sshd_config.

Adding a “useDNS no” line to /etc/ssh/sshd_config made my ssh login via Putty happen much faster.

Advertisements
Posted in Ruby

Copying Ruby objects: to dup or clone or “=”?

…That is the question!

The Stackoverflow discussion linked to here contains a number of useful bits and bobs with regard to elucidating the difference between the dup and clone methods, and also using “=” to copy a value.

Ruby – DUP vs CLONE

Both DUP & CLONE can be used to create shallow copy of an object. Both copies the instance variables of obj. But we need to be selective in their usage.Few difference between these are1) CLONE copies both FROZEN and TAINTED state of an object, where as DUP only copies TAINTED state of an object.2) With CLONE you can copy any singleton methods of an object but DUP does not support this.

CLONE is used to duplicate an object, including its internal state, DUP typically uses the class of the descendent object to create the new instance.

Open source is wide open

Operator “=” does not make a copy, shallow or tainted: it will merely copy the object reference.

A good article on Object states can be found here.

Posted in Ruby

Why use a Ruby symbol?

The Ruby Newbie Guide to Symbols is a decent introduction to symbols in Ruby, though it doesn’t get into how symbols actually are implemented within the system. In short, though:

  • The only reason that symbols could be found preferable over strings is because they save on data, this because every use of the same symbol refers to the same object. Even though the programmer refers to it with its name the system can find it by referring to its number, which results in a faster lookup.
    • Note however that Symbols of course will not have String methods, so are relatively deficient if what you really want is a string with all its inherent string functionality.
  • The things a programmer might find valuable about a using symbol is that it’s immutable (it can’t be changed on runtime) – which sometimes is exactly what you want. In this respect, they can be used as constants – perhaps if you really, really want a constant whose identifier doesn’t begin with a capital letter.
    • Arguments for taking such an approach? Because you benefit from abiding by variable-naming conventions (for example, Ruby doesn’t enforce the constancy of constants, but variables that start with a capital letter in Ruby are automatically constants, and Ruby does automatically and helpfully warn you if you try to change these), and a constant with a non-uppercase first letter breaks conventions and thus could cause confusion to people reading your code. As such, a symbol – which is by its nature immutable – is a good choice both in terms of being functionally what you’re after (ie you can’t change its value) and for communicating to readers of your code that the variable in question, even with its non-uppercase first letter, really is a constant.

The Difference Between Ruby Symbols and Strings also emphasises the way that symbols are immutable, and the more predictable results + performance you therefore get when using them.

Posted in Typography

Some Handy Typography Resources

Software Bits and Bobs
Learning From Others
  • WhatFont is a tool that can be installed to your browser (as an add-on if you’re using Chrome, or a bookmarklet for Firefox) that allows you to instantly view information about any font used on any webpage in a popup just by waggling your mouse over it.
  • FontFinder is a Firefox-specific add-on with similar functionality, giving you even more information (including CSS styles applied), though the bucketloads of super-useful details you get (in a basic JavaScript alert window) do come at the expense of the aesthetic appeal WhatFont boasts. Decisions, decisions…!
Web Dev Tools and Resources
Other (Theoretical Things)
Posted in WordPress

Anti-spam plugin for WordPress

I was having a spam problem on a website I look after recently and thought I’d try an alternative to Akismet, since the latter now needs to be paid for on commercial websites. I installed Anti-spam, which uses a honeypot style trap to catch bots, and left on the core WordPress setting where problem comments are emailed to you, so as to keep an eye on things.

Well, the spam comments came in: all the usual rot, just now largely getting rejected (though notifications are sent to me by email) rather than marked as spam but still requiring me or my client to sort through them and delete them. I’m satisfied enough to switch the email option off and let it do its thing silently from here.

The honeypot technique won’t stop manual spammers (though there’s a paid version that claims to be able to ward off 70% of them) but it’s taken care of a good chunk of the problem. If it ramps up again, the paid version at $14 might be worth a stab.

Posted in WordPress

Definition of a WordPress hook

Hooks.

The term confused me for ages when I first started looking into WordPress plugin development. Anything I’ve learned about them I feel like I’ve done despite rather than because of the tutorials I consulted about them. Feeling like you’ve missed something can really undermine the learning process and chip away at the satisfaction you feel about doing things right.

So it’s nice to read an article whose author notes specifically that the term is often used incorrectly and confusingly to refer to two different things:

Just as in pop-music, the term “hook” is sometimes ambiguous—different people use the term to refer to different things. Technically, the term “hook” should refer to a WordPress event, such as get_header or the_content, but sometimes it is used generally to refer to the add_action() or add_filter() functions which reference the hook. Pay attention to the context, and it should be clear which meaning was intended. The most important thing to understand here is that you determine when your functions execute by attaching them to a WordPress event by using the add_action() or add_filter() functions. Remember: hooks are events.

From Anatomy of a WordPress Plugin, which incidentally is all quite well-explained.