Monday, 26 November 2012

Find all files and move to a target directory from the Linux command line

For this example, we're going to be moving all .mp3 files from the subdirectories of the current directory into current directory.

To do this, we need to combine two different commands. To find all the files in the current directory and its subdirectories, we use the find command:
 find -name \*.mp3  

The \ escapes the *, so it's interpreted as a wild card on the command line. The -name argument allows us to check only the file names.

To move files around on the command line, we use the mv command, and for our example, we add the -t argument, which lets us define the target directory:
 mv -t <target-directory> <file-to-move>
where target-directory is where we want to move the file to, and file-to-move is the file we want to move.

With a bit of command-line magic, we can combine these commands using the -exec switch on find, to give us our final command:
 find -name \*.mp3 -exec mv -t . {} \+  
-exec takes the command we want to execute, and {} \+ appends each find result to the command, which in our case is mv. So the above line will find all files end in .mp3 and move them to the current directory.

Monday, 19 November 2012

Fail Fast - A Lesson In Not Wasting Time


fail fast




Around a year ago, I had an idea for a small browser based application that had the potential to smooth and streamline a workflow within universities around the country. The concept was simple and wouldn't have taken a huge amount of time to develop. Given my position working in a university setting, I had the ideal environment to test and prototype, but due to constraints on my time I didn't take the concept any further.

Fast forward to last week. I'd finally found the inspiration, motivation, and time to solidify and explore this idea. It took me less than an hour to map out the specifics of my concept, and email a few academic contacts to see what they thought of the idea. Feedback was positive; I'd found a niche. Unfortunately, the very same week, the university have announced that they are trialling a new, much larger system which implements a substantial feature list, and includes the subset of functionality I was aiming to provide.

Why do I tell you this story? Well, there's lessons here. Despite my initial disappointment, this is a perfect example of failing fast and learning quickly. While there was a part of me that felt I shouldn't release my idea into the world until I had built the application and had a full, perfect implementation to demonstrate, had I done this I would have committed hours, days, or weeks of my time to building a system that had zero chance of ever being used. Here's what this experience taught me:
  1. Talk about your ideas. It's natural to feel protective of your concepts, and worry that they might be stolen or plagiarised (or laughed at - see 3.). In my experience, it's highly unlikely that they will, and if they do, talking to enough people makes it clear where the idea originated. The knowledge and insights you stand to gain from sharing knowledge and ideas far outweigh any perceived risks of collaboration.
  2. Act Early. If you have an idea, or discover a niche you could occupy, act on it early. If I'd had the confidence to explore my concept a year earlier, I'd have been first to market, so to speak, and would have been in a much better position to compete with the larger system that has come along now. Who knows, I might have gained enough traction to have become that larger system.
  3. Fight your inner perfectionism. The world is imperfect, and so your contributions to it can be too. Don't spend forever perfecting designs, ideas and implementations. However scary it might be, put yourself and your ideas out there, and you'll be pleasantly surprised at the what happens.
So there we have it, it took me less than a day to establish that, despite a market need, my good idea wasn't commercially viable in current circumstances. My time is now free to explore my next project. Next time you find yourself thinking "maybe there's a need for this... one day I'll have the time..." - take the time to explore, find feedback and fail fast or fly.


[Image credit] http://thumannresources.files.wordpress.com

Friday, 16 November 2012

Finding out what Matlab tooboxes are available for use

Finding out what toolboxes are available to a Matlab installation is actually relatively simple - it's just a case of typing:
 ver  

at the Matlab prompt.

On it's own, however, this function doesn't supply much useful information, as it doesn't tell you what licences are available to the installation, and hence which toolboxes you can actually use (which is probably what you care about when you're trying to find out what toolboxes are available).

It is possible to find out what licenses are available to the installation, however it takes a bit more work.

First, we need to define a feature string, which is just a list of all the toolboxes potentially installed:
 featureStr = {'Aerospace_Blockset'; ...  
        'Aerospace_Toolbox'; ...  
        'Bioinformatics_Toolbox'; ...  
        'Communication_Blocks'; ...  
        'Communication_Toolbox'; ...  
        'Compiler'; ...  
        'Control_Toolbox'; ...  
        'Curve_Fitting_Toolbox'; ...  
        'Data_Acq_Toolbox'; ...  
        'Database_Toolbox'; ...  
        'Datafeed_Toolbox'; ...  
        'Dial_and_Gauge_Blocks'; ...  
        'Distrib_Computing_Toolbox'; ...  
        'Econometrics_Toolbox'; ...  
        'EDA_Simulator_Link_DS'; ...  
        'Embedded_Target_c166'; ...  
        'Embedded_Target_c2000'; ...  
        'Embedded_Target_c6000'; ...  
        'Embedded_Target_MPC555'; ...  
        'Excel_Link'; ...  
        'Filter_Design_HDL_Coder'; ...  
        'Filter_Design_Toolbox'; ...  
        'Fin_Derivatives_Toolbox'; ...  
        'Financial_Toolbox'; ...  
        'Fixed_Income_Toolbox'; ...  
        'Fixed_Point_Toolbox'; ...  
        'Fixed-Point_Blocks'; ...  
        'Fuzzy_Toolbox'; ...  
        'GADS_Toolbox'; ...  
        'IDE_Link_MU'; ...  
        'Identification_Toolbox'; ...  
        'Image_Acquisition_Toolbox'; ...  
        'Image_Toolbox'; ...  
        'Instr_Control_Toolbox'; ...  
        'Link_for_Incisive'; ...  
        'Link_for_ModelSim'; ...  
        'Link_for_Tasking'; ...  
        'Link_for_VisualDSP'; ...  
        'MAP_Toolbox'; ...  
        'MATLAB'; ...  
        'MATLAB_Builder_for_dot_Net'; ...  
        'MATLAB_Builder_for_Java'; ...  
        'MATLAB_Distrib_Comp_Engine'; ...  
        'MATLAB_Excel_Builder'; ...  
        'MATLAB_Link_for_CCS'; ...  
        'MATLAB_Report_Gen'; ...  
        'MBC_Toolbox'; ...  
        'MPC_Toolbox'; ...  
        'NCD_Toolbox'; ...  
        'Neural_Network_Toolbox'; ...  
        'OPC_Toolbox'; ...  
        'Optimization_Toolbox'; ...  
        'PDE_Toolbox'; ...  
        'Power_System_Blocks'; ...  
        'Real-Time_Win_Target'; ...  
        'Real-Time_Workshop'; ...  
        'RF_Blockset'; ...  
        'RF_Toolbox'; ...  
        'Robust_Toolbox'; ...  
        'RTW_Embedded_Coder'; ...  
        'Signal_Blocks'; ...  
        'Signal_Toolbox'; ...  
        'SimBiology'; ...  
        'SimDriveline'; ...  
        'SimElectronics'; ...  
        'SimEvents'; ...  
        'SimHydraulics'; ...  
        'SimMechanics'; ...  
        'Simscape'; ...  
        'SIMULINK'; ...  
        'Simulink_Control_Design'; ...  
        'Simulink_Design_Verifier'; ...  
        'Simulink_HDL_Coder'; ...  
        'Simulink_Param_Estimation'; ...  
        'SIMULINK_Report_Gen'; ...  
        'SL_Verification_Validation'; ...  
        'Spline_Toolbox'; ...  
        'Stateflow'; ...  
        'Stateflow_Coder'; ...  
        'Statistics_Toolbox'; ...  
        'Symbolic_Toolbox'; ...  
        'SystemTest'; ...  
        'Video_and_Image_Blockset'; ...  
        'Virtual_Reality_Toolbox'; ...  
        'Wavelet_Toolbox'; ...  
        'XPC_Embedded_Option'; ...  
        'XPC_Target'};  

That's a lot of typing, so I'd just copy and paste from above, into your Matlab prompt.

Next, we want to check that licenses exist for each of the items in the above list:
 index = cellfun(@(f) license('test',f),featureStr);  
 availableFeatures = featureStr(logical(index));  

Licences that exist are now stored in availableFeatures, so typing that at the prompt gives us a list of licences that are available to the installation:
 availableFeatures  

To see if a single license exists, we can also simply supply license('test',<feature_name>) with the single feature string we care about. For example:
 license('test', 'Neural_Network_Toolbox')  

This is normally as much information as we need, but if we need to know if a licence is available to checkout at the present time, we can continue as below.

NB: Using license('checkout',<license>), as described below, is not normally a good idea when using network licences, as the license will not be released until Matlab is shut down. Usually, licenses are checked out automatically, as and when they are required by a toolbox.

So far, we've found out whether or not a license exists, but not if one is presently available for us to check out. To actually checkout a license, such as the Signal Toolbox, we can do:
 license('checkout','Signal_Toolbox')  
Where Signal_Toolbox comes for the feature string list at the top of this post.

If Matlab returns:
 ans = 1  

Then the license checkout was successful. We can also look at the licenses we currently have checked out out using:
 license('inuse')  

As usual, I hope this has been helpful, and feel free to add any notes or observations in the comments below.

References:

  1. Matlab documentation: license()
  2. Matlab newsgroup: License checking
  3. StackOverflow: How would one check for installed MATLAB toolboxes in a script/function?


Tuesday, 6 November 2012

Fixing Print Screen in Linux Mint XFCE

To enable Print Screen key functionality in Linux Mint XFCE:

Ensure xfce4-screenshooter is installed:
 sudo apt-get install xfce4-screenshooter  

Then, in the Menu, go to Settings -> Keyboard then Application Shortcuts -> Add. In the Command field, enter xfce4-screenshooter and then click OK, before pressing the Print Screen key on the keyboard, to set that shortcut.

Remote Desktop in Ubuntu 12.04

This is the first post in a three part series exploring Ubuntu-based remote desktop options. See posts two and three for further exploration and conclusions.

In my opinion, both of the mainstream remote desktop/windowing approaches in Linux do not compare with the ease of use, and the speed of Windows remote desktop. VNC is inherently insecure, and setting up VNC over an SSH tunnel isn't the most user friendly of experiences. X forwarding over SSH is better, but in my experience there's simply too much latency when using it outside a LAN. Enter NX, or NoMachine - the only Linux remote desktop solution I've come across used that isn't a pain to get up and running, and is more than fast enough to be useable.

Here's what you need to do to get going with NoMachine. Below, target machine refers to the machine you want to connect to, and client machine refers to the machine you are connecting from.

On the target machine:

If it's not already installed, add openssh server to your machine:
 sudo apt-get install openssh-server  

Add the FreeNX repository to your system using:
 sudo add-apt-repository ppa:freenx-team  

Then install FreeNX with:
 sudo apt-get update  
 sudo apt-get install freenx  

As Unity3D is too heavy to use over a WAN connection, allow fallback to a gnome session:
 sudo apt-get install gnome-session-fallback  

On the client machine:
Use the NX client of your choice - personally I used Remmina, with the Remmina NX plugin: Update: While Remmina works well, the offical NX client gives a lot more options - see below for more.
 sudo apt-get install remmina
 sudo apt-get install remmina-plugin-nx

Start Remmina, and create a new connection. You should now be able to choose to connect using the NX protocol, as seen below.

Enter the target machine's IP address into the server field, and the username and password of the user account you wish to connect to. Hit connect and after a few moments your remote desktop will open.


You can also use the official NX client, and if you're connecting from Windows or Mac, that's probably easiest. For Linux, the official client download and install instructions are currently here.


I've not yet had the chance to experiment, but it may be possible to run the NX client from a different desktop on the target machine - if so, then this would make NX a complete, drop in replacement for Windows remote desktop, as far as I can see. Which is no bad thing, as other than the obvious proprietary graphics issues Linux can suffer from, a decent RDP implementation was the only only key feature I've noticeably missed since moving to Linux full-time (yes, there's X forwarding over SSH, but even with compression there's still too much lag to be usable over my connections). Update: It looks like the official NX client has a shadowing mode - again, I've not yet tested it, but it may be useful for the above.

Update Nov-16-2012: As noted in the comments, Cendio also offer a Linux remote desktop solution - after testing and comparing, my thoughts can be found in post two.


Monday, 5 November 2012

Installing the latest version of R into Debian Stable

The R packages available in the Debian repository are are little out of date - to install the latest (stable) version we need to add a backports repository. Just follow the steps below!

Open the sources list with:
 sudo nano /etc/apt/sources.list  

Then add this line to the bottom of the file (use your favourite mirror if desired):
 deb http://cran.ma.imperial.ac.uk/bin/linux/debian squeeze-cran/  

The Debian backports are signed with the key of "Johannes Ranke (CRAN Debian archive) <jranke@uni-bremen.de>", with key ID 381BA480 . Import this using:
 sudo apt-key adv --keyserver subkeys.pgp.net --recv-key 381BA480  

Then, update the packages cache - this should complete without errors.
 sudo apt-get update  

Finally, install R and the R recommended packages using:
 sudo apt-get r-base r-recommended   

To check the version of R that is now installed, use:
 R --version  

To start R, simply type
 R  

at a command prompt. As usual, let me know of any issues or problems in the comments below.