Categories: Linux, Software Development

PHPUnit Essentials Book Review

PHPUnit Essentials would have come in handy while on a recent contracting gig and on all the other PHP projects I’ve worked on. The book is published by Packt Publishing, the last book I bought from them was on AngularJS and it was a great guide whereas as the O’Reilly book on AngularJS was outdated.

Overall the book was a good read and it’s worth getting as both a guide and a reference.
Continue reading “PHPUnit Essentials Book Review”

Categories: Linux, Software Development, Utilities

Installing NPM from NodeJS source

Node.js Logo

The latest versions of NodeJS apparently come with npm. Here’s how to install it.

  1. Download nodejs source: http://nodejs.org/download/
  2. Decompress it:
    tar zxvf node-x.y.z.tar.gz
  3. Enter the deps/npm directory:
    cd node-x.y.z/deps/npm
  4. Run the standard install process:
    ./configure
    make
    sudo make install

You can also use `make latest` to install the latest version of npm. Using `make install` or `make link`install npm from the source directory.

Rant

The docs for npm mention that but don’t tell you how to install npm system-wide. They simply recommend you download some random shell script and run it. Downloading and running a shell script directly from the internet is a dangerous proposition and something you should never ever ever ever ever ever ever do.

If you wouldn’t run random Linux commands from an IRC chatroom, you shouldn’t run a random install script from the internet.

Categories: Linux, Software Development, Utilities

GreaseMonkey and Stylish for custom JS and CSS in your browser

I just stumbled upon a few repos on Gitub for injecting custom CSS and JS into web pages that are loaded into your browser: dotcss and dotjs. Not to take away anything from the developers but GreaseMonkey has been around for a long time and works with both Firefox and Chrome whereas dotjs does not. Ditto for Stylish. I remember using both of them in Firefox a long time ago (5-6 years ago).

If dotcss and dotjs are provable better than GreaseMonkey and Stylish I’ll be impressed but as it is, they look like they require a web server, a bunch of Ruby code and a Rakefile (a.k.a. build/Makefile). Seems like overkill for a bit of extra convenience.

A criticism of GreaseMonkey is that after editing you need to republish it:

GreaseMonkey user scripts are great, but you need to publish them somewhere and re-publish after making modifications. With dotjs, just add or edit files in ~/.js.

I don’t think I’ve encountered this problem. My scripts were saved in some random folder and then I just reloaded the page. No need to publish them anywhere else. Same with Stylish.

Running multiple web servers is definitely overkill. If you’re going to override the JS/CSS of a website, I suggest using GreaseMonkey and Stylish instead.

Click here for 100 ingenious GreaseMonkey Hacks

Categories: Linux, Software Development

First code patch submission in a long time…

UPDATE: It got in, the patch was reviewed, updated and added to the main code base. The developer even added my name to the credits!

I submitted an issue to the Django Rest Framework project. There was a bit of a problem with the documentation’s example not reflecting the code. The oft-repeated “the docs are never updated with the code” line that other programmers like so much ran through my head.

I think the way I presented the issue was solid…providing enough detail about what I was trying to do, the code that failed, the error message that was trigged, the version of the framework I’m using, and pointing the area of the code base that potentially caused my issue: https://github.com/tomchristie/django-rest-framework/issues/955

To remedy this situation, I forked the repository, created a new branch, made the fix, and created a pull request: https://github.com/tomchristie/django-rest-framework/pull/956

Documentation is important, especially when a project has over 1000 users. Updating it should be seen the same way as fixing code or adding new features, it shouldn’t be seen as a chore. As I quoted in a previous post, “some text is better than no text”.

The author of Django Rest Framework, Tom Christie, was super quick to respond. I got a response to the issue within a few hours. The frequency of releases isn’t too bad either, it feels regular and I would definitely continue using the project over tastypie.

I haven’t submitted a patch to any project in a long time, I’ve only reported a few issues and it will be awesome if this patch is accepted.

Generating a Culture of Code Documentation

Generating a Culture of Code Documentation

This is from a presentation given at the Write the Docs conference,

Cutter’s experience is that SMEs fall into three categories in roughly equal proportion: eager to help, willing to help (with guidance in the form of templates and direction), and curmudgeons.

…You as a writer have knowledge that engineers need to help them write docs effectively, and when you share that knowledge you help them write more docs. Hold doc office hours where you’re available to help them with docs. Because some text is better than no text.

Curmudgeons will say “but code documents itself!” Cutter calls “bull”; code only tells what it does, not its intent. [NB: Intent is worthless if the code’s action doesn’t match it.] Even if you know what you wrote immediately after you wrote it, six months later you’ll have moved on and that’s when the documentation becomes critical.

Categories: Linux, Software Development

Python Exceptions

http://www.jeffknupp.com/blog/2013/02/06/write-cleaner-python-use-exceptions/

Many programmers have had it drilled into their head that exceptions, in any language, should only be used in truly exceptional cases. They’re wrong. The Python community’s approach to exceptions leads to cleaner code that’s easier to read. And that’s without the monstrous hit to performance commonly associated with exceptions in other languages.

There’s a nice point made about exceptions vs error codes on the c2 wiki:

If you don’t explicitly handle an exception, Something Bad Happens, and that is a Good Thing. Consider the consumer and producer of some facility – in the simplest case, one method calling another. If the consumer is written by a conscientious programmer, then s/he will check the return value / catch the exception (or knowingly allow the exception to bubble higher). In this case, the overall system works well, no matter if the facility producer (the method called) throws an exception / returns an error condition or not.

 

However, if the caller is written sloppily, or quickly, it is unlikely that the caller will check the return value / catch the exception (when appropriate). If you use return values, the error is simply lost, and the internal logical consistency of your system has just been – silently! – destroyed. Your system may continue to do something useful, but most likely, it will fail in a subtle, hard-to-diagnose fashion.

Categories: Linux, Utilities

GNU Moe Tutorial/Review

Yesterday I was looking at a listing of updates for free software projects. I commented that the package GNU Moe could be used as a replacement for nano or zile, that is, when you need to quickly edit files from the command-line.

So today I’m giving it a go. I downloaded moe via the GNU project’s FTP server and installed it. The compilation was insanely fast, I think it took less than 10 seconds to get it all built and installed.

This blog post is a small tutorial (and a bit of a review) for using GNU Moe and is actually being written in it. I’m learning as I’m doing and this is usually the best way to learn anything. The manual for moe is, well it doesn’t exist. When you first enter moe you are confronted with a blank screen and a title bar at the top of it.

The title bar lists:

  • the command key being used (if any)
  • the current mode of the text editor, either “I” for “Insert” or “O” for “Overwrite”
  • the name of the file being edited
  • whether it has been modified and needs to be save
  • which line you are on
  • which column you are at
  • the time (in 12-hour clock with no AM/PM indicator)
  • a helpful reminder telling you to press “F1 for help”

In comparison, nano only tells you the version of GNU nano that you are using and the name of the file. Nano also helpfully lists some commands at the bottom of its screen.

Press F1 For Help

The first command key I used was of course "F1", the help key. GNU Moe uses the function keys for saving files, loading files, undo and redo, the options menu, the buffers menu and some other things which I will get into as I come across them.

The second command key that I used was Ctrl+C. If the current file being edited is Modified, it will ask if you want to “lose your changes”. If you press “n” meaning “No I don’t want to lose my changes”, it will save the file. I think this is better than asking if you want to save your changes. The way the question is posed is different and highlights the fact that you will lose whatever you were working on.

GNU Moe Gets Out Of The Way When Typing

In terms of typing, GNU Moe hasn’t gotten in the way at all. In fact, it has provided two useful command keys; Ctrl+Y which kills/deletes a whole line of text, and Ctrl+B which re-formats a paragraph by wrapping it at a certain column (I think column 72). The re-formatting is very useful when you’re on a regular terminal. Right now I’m in the shell that you get before running any desktop system. The screen can only handle 80-character columns right now. You can set the column to whatever you like in the Options menu (accessed by pressing F10).

Okay, I just pressed F2 to save the file. It asked me for a new name or location for the file, but luckily it already provides the same name as before. So saving the changes is a matter of pressing F2 and then the Enter key. You can also save and exit moe by pressing Ctrl+X. After I’m done typing here, I’ll definitely be using that, heh.

To load a file, you press F3. As soon as you open more than one file, they are loaded into separate buffers and then moe gives you access to the buffer menu. You can access it by pressing F11 and it lets you switch between the different buffers by choosing from the menu or pressing a number key. To get rid of the buffer, you press Ctrl+C.

So far GNU Moe is very easy to deal with, it all seems self-explanatory.

One thing to watch out for is the behaviour of whatever terminal you’re using. The GNOME Terminal wouldn’t let me use the function keys properly and the same was true of xterm. Another thing is the key bindings. They’re kinda like Emacs’s key chords, though not all of them are like that. There are four different prefixes for the key chords: “[“, “O“, “Q“, “S“. The first prefix is the most commonly used one, while the other three are used for special commands.

If you’re interested in IDEs rather than simple text editors, I recommend checking out PyCharm if you’re a Python developer and either Emacs or Intellij IDEA if you use other programming languages.

Categories: Linux, Software Development

Free Software Supporter #18 announces some recent GNU software releases

Free Software Supporter is a newsletter run by the FSF (Free Software Foundation) and in it they have a section announcing a few software releases from the GNU project. However, they do not seem to provide any description of the projects aside from their name and version.

I guess this is okay since Free Software Supporter readers may only be interested in particular software packages and may already know what they do. But for me, it’s just a list of random names and numbers that don’t mean much at all.

Here’s the list and a few brief sentences about them. Some of them look useful and might help us programmers avoid re-inventing the wheel!

acct-6.5.1, The GNU Accounting Utilities are used for recording information about system usage by users. This would be useful for system administrators because they can see a history of past usage by user. The preface to the manual is awesome awesome. It begins with this line:

Way back a long time ago, Thompson and Ritchie were sitting opposite one another at the commissary, sipping coffees and discussing their evolving behemoth.

ccscript-4.1.2, ccscript3-1.1.7, GNU ccScript3 seems to be useful for creating scripting languages to use with C++ applications. Their website says,

GNU ccScript is a C++ class framework for creating a virtual machine execution system for use with and as a scripting/assembler language for state-transition driven realtime systems. The most common example of this is as the core of the scripting engine found in GNU Bayonne.

I haven’t ever seen this in action but it sounds a little interesting.

coreutils-7.5, GNU Core Utilities are the standard GNU/Linux utilities. These are basically cdls, and other things like that. Obviously very useful for everyone.

Here are some utilities that I haven’t even heard about before:

freeipmi-0.7.12, GNU FreeIPMI is used for managing IPMI stuff. I have no idea what that means, so here’s the excerpt from their homepage explaining it:

The IPMI specification defines a set of interfaces for platform management and is implemented by a number vendors for system management. The features of IPMI that most users will be interested in are sensor monitoring, system event monitoring, power control, and serial-over-LAN (SOL).

So I guess it’s meant for managing large amounts of computers. Handy for system administrators for sure.

gengen-1.4, GNU Gengen (it stands for GNU GENerator GENerator) is like a template generator for C/C++. It’s not like C++ templates or meta-programming, I think it’s more like Lisp’s macros. The variable names (the symbols of them if you will) can be substituted into a template. This is somewhat like the C pre-processor macros but I think it’s a bit more powerful. I can’t see myself using this though so I can’t explain its usefulness any more than that. Read this section to see how Gengen could help you.

gsl-1.13, the GNU Scientific Library contains a collection of science-related calculation functions such as those for dealing with polynomials, vectors, matrices, sorting, etc. It is easy to see how this could of use to a large number of developers.

libsigsegv-2.7, GNU libsigsegv is a “library for handling page faults in user mode. A page fault occurs when a program tries to access to a region of memory that is currently not available”. This library is useful for developers, in particular for systems developers.

libunistring-0.9.1.1, GNU libunistring is a C library for handling Unicode text and is useful for developers dealing with Unicode text. Note that this library isn’t for providing translations, that’s what GNU gettext is for.

moe-1.3, GNU Moe is a text editor with a file size of less than 500KB. It has a lot cool stuff in it even though it’s so small. According to the README, there is no learning curve. Some experience with a text editor and a look at the README and apparently you’re set to use moe. I’m going to download it and I’ll see if it’s a good replacement for nano and zile.

mtools-4.0.11, Mtools is utility tool collection for dealing with the MS-DOS filesystem. It has the basic tools needed to make use of the file system, such as a list directory utility, and another one for formatting a disk. This is useful for archival purposes or when dealing with legacy machines. I’m not sure recent versions of Windows use the MS-DOS filesystem for much 😉

reftex-4.34, RefTeX is a package for automating labeling, referencing and citing other articles. It is used with LaTeX and BibTeX. I might have to check this out the next time I’m writing a paper for college/university.

sipwitch-0.5.7, GNU SIP Witch is a SIP server. Basically, “GNU SIP Witch can be used to build secure and intercept-free telephone systems”. Again, this is useful for system administrators to know about, but isn’t very interesting for me.

vc-dwim-1.2vc-dwim is very useful for programmers because it keeps track of discrepencies between version control and ChangeLogs. The coolest thing is that it can commit changes to files that have been mentioned in the ChangeLog, the unmentioned files won’t be committed. This makes it very easy to keep the version control commits and ChangeLog synchronized. I know I’ve forgotten to update the ChangeLog many many times.

xboard-4.4.0, GNU XBoard is a GUI for chess. It lets you use various chess engines to play. It handles a few different variations of the game too. I may check it out, I’ve been using eboard for a bit now.

zile-2.3.10, GNU Zile (which stands for Zile is Lossy Emacs) is a small text editor modeled on Emacs. It provides the same key-bindings and some useful commands. I’ve been using it as a replacement for nano and vi. The size of it is less than 500KB too.

NeverFriday Software Expertise Proudly powered by WordPress , Theme designed by FancyThemes