Wednesday, May 27, 2009

Linux: Looking at files changed recently

This is really handy (on Linux and Cygwin) when you're working on a project that may not be in source control and you want to see what you changed recently.

I made this blog post, when it seems a trivial use of find, because I don't think the man page covers it well.

This command finds all files modified in the last 60 minutes:

find . -type f -cmin -60

Thursday, May 14, 2009

Linking MingW32 with psapi

Here's something I came across that didn't have a good answer when I googled. If you get link errors with MingW32 like:

undefined reference to `GetProcessMemoryInfo@12' or
c:/justinhj/mem.cpp:55: undefined reference to `EnumProcesses@12'

Then you are not linking with the library psapi, and you need it.

To do this just add -lpsapi to your command line. It needs to be last in the list of libraries too!

Writing quick C++ programs in emacs without a makefile



Cheetah by Storm Crypt

Often when programming in C++ (or many other languages) it's desirable to write a quick program, usually a console application, to test something quickly. Working in developer studio, it takes an amount of fiddling and clicking large enough that you may not want to bother.

Working in emacs and MingW32 (or Microsoft's CL.exe) I can quickly create a CPP file, and then compile it. To compile a program though you need to either write a makefile, or build up a complex g++ command line.

Rather than do either of those I make a helloworld.cpp file which can be built like this:

g++ helloworld.cpp -g -o helloworld.exe

So I hit

M-x compile

then type in the above to compile and link it.

However there's a better way. You can add the compile command as the first line of the file as a file local variable.

// -*- compile-command:"g++ helloworld.cpp -g -o helloworld.exe"; -*-

Now I can hit the compile and it works right away, between sessions. No makefile or project settings in sight, and now there are minimal barriers involved in creating a simple test program beyond copy and pasting the file.

Tuesday, May 12, 2009

Converting flac to mp3

This is just a link to a great description of converting flac to mp3 files. There's a tonne of commercial and useless sites that try to answer this question

So I thought I'd add another link to this one that actually works, and uses free software.

http://www.afterdawn.com/guides/archive/how_to_convert_flac_files_to_mp3.cfm

Friday, May 8, 2009

emacs: Renaming multiple files at once with a regular expression

M-x dired
(navigate to the folder)
M-x wdired-change-to-wdired-mode
M-x replace-regexp
(enter search and replace expressions)
C-c C-c

Which writes out the changes to the directory.

Thursday, May 7, 2009

emacs: Searching programming API's with webjump


Image by MarkyBon

In a previous post I outlined how to use webjump, a built in feature of emacs to quickly launch web pages in a browser, after querying the user for search phrases and so on.

This describes how to simply setup webjump to search the API documentation for whatever framework you are using. The example will be Java's Platform documentation. 



  1. Find the base url you want to search. We will use google to only find things that begin with this. In the case of Javas documentation I'm going to search at http://java.sun.com/javase/6/docs/api/
  2. Set up the web jump code as below. The three arguments in square brackets are [ base url, normal search url prefix, search url post fix ]. You just need to replace the JAVA API part of my URL with the URL you are interested in.
  3. M-x webjump
  4. Type your query and hit enter
  5. Browser opens with search results






(require 'webjump)
(global-set-key [f2] 'webjump)
(setq webjump-sites
(append '(
("Java API" .
[simple-query "www.google.com" "http://www.google.ca/search?hl=en&as_sitesearch=http://java.sun.com/javase/6/docs/api/&q=" ""])
)
webjump-sample-sites))