Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Tuesday, 18 August 2015

Tree keeping made easy

If you want snazzy tree views for your project of your local drive files and the remote master repository that you can traverse with a browser, just modify this script and set up a cronjob to keep your trees updated.

How does it look?

Download the file itself, load it into your browser and have fun traversing the tree of the Corinthia GitHub repository. (blogger.com and google.drive won't let me paste the file without crippling the links, fair enough, it's 168 directories (and thus links) and usually people who do this kind of thing would probably be up to no good[1]).  If you just want to see it without working links, it's here.




I think it's nice to have a tree overview --- a picture is worth a 1000 words (as they say).

[1] sadly, saving the document also ninja-edits the original.  So, don't waste your time with pasting lots of links into Google Docs :(

Sunday, 9 August 2015

Adhoc profiling

./YourProgram | ts -i "%.s"

is a quick way of profiling your code.  Does of course not beat the real thing(tm), but for most purposes, this should give you a rough idea where your code spends it's time.

(You may need to install 'moreutils')

Some hacking music... because otherwise, there is just too much margin left in this blog post.


Tuesday, 5 May 2015

How to grab every mp3 from a Feedburner page

My little Apple finally died[1] and the major loss was my collection of the entire History of Rome podcast, by Mike Duncan.  Oh noes!

Sadly, Feedburner doesn't provide a big zip file of all the episodes, which is understandable, since it would be huge.

I could hunt around for a browser extension that does a mass download, but this is quicker, safer and way more fun:

Save the above file to your 'history_of_rome' directory as 'hist.xml'

Preferably overnight(if your 'broadband' comes via the phone line...), in the bash shell do this:

$ grep -e "enclosure url=" hist.xml | sed -e 's/[^"]*"//' -e 's/".*//' | xargs wget

And hopefully, if all goes well, in the morning you'll have this:

FINISHED --2015-05-05 02:06:31--
Total wall clock time: 2h 26m 38s
Downloaded: 191 files, 2.0G in 2h 24m 49s (240 KB/s)

~/history_of_rome>

You say that this podcast is a little bit short for such a long story?  Well, there's lots more out there, but this is my second favourite series:



[1] And, after all this, I found that the Apple actually wasn't broken, but the USB port I plugged in for a recharge was.  ;-D

Friday, 17 April 2015

I installed tree and found a useful forest

Today I was idly reading some random unixy stuff, and, came across the 'tree' command.

I had to install it for Ubuntu, but, it definitely was well worth it.

It's s useful if you are connecting with a shell and need to navigate a forest, and also makes a neat html file from any tree you like, which looks good in lynx, or in any web browser for that matter.

The tree gives you the big picture, with tree -d -H . > tree.html


(OMG, I'll be whistling this all day long now.  And so will you ;-D )

Tuesday, 16 September 2014

Om Nom Nom.

I'm having a tough time.

I signed up for the Coursera Automata Class, and it reminds me of the Schraraffenland Fairytale: to get to the fabled country where delicious fried birds fly into your mouth and pralines grow from bushes, you have to eat your way through a mountain of pumpernickel.

Om nom nom. 

(I will probably need to take this class twice, once for the measure, once to sink in)

File under:
'And you do Addition?' the White Queen asked. 'What's one and one and one and one and one and one and one and one and one and one?' 'I don't know,' said Alice. 'I lost count.' 'She can't do Addition,' the Red Queen interrupted.
                                                                           Through the Looking-glass

(Maybe I should make this into a t-shirt ;-)

I'm also reading through 'The Linux Programming Interface'  book and I'm now starting to cycle down into re-reading the chapters and doing the exercises [(I'm half-way through the book in the first sitting, time for some action), and whilst I'm having fun learning the basics, maybe you would enjoy refining your systems programming jutsu at the same time and heckle a beginner in style ;-)]

If you want to pile in, mail me.

Music I'm listening to:


(this is probably more 'ye olde jazz head stuff' -- but if you spool forward a bit to 10:35, you find some easier listening.  That said, Michel Petrucciani is just wonderful.  Yeah, some stuff is wild, but it always has soul(and much jump). Lots of it.)

Finally, my latest culinary foible is 'sharpening carrots':

See it in action:


Stuff the resulting peel with anything!  Om Nom Nom :-)

{{{ Life is good! }}}

Tuesday, 2 September 2014

...and the crowd goes wild!

"SIGSEGV
This very popular signal is generated when a program makes an invalid memory reference."

(From THE LINUX PROGRAMMING INTERFACE by Michael Kerrisk.)

Sunday, 3 August 2014

Remedial Reading for the 'C'onfused.

Programming from the Ground up is an easy going, fun read, and goes a long way towards explaining all those inconvenient miracles that occur when you first try to use pointers in C.




... and, for some reason, Holger Czukays' short video of 'Ode To Perfume' nicely matches the topic (and it's pretty good hacking music).  The longer version of that song is here

(and if this reminds you of Stockhausen's work, well, there's a reason for that)

Update: This here is also a useful read about C's peculiarities.

Saturday, 21 June 2014

It Seemed Like a Good Idea at the Time

My latest idea for the svn --diff-cmd can be seen here.


Let's hope it does better than this guys' great idea!

Thursday, 29 May 2014

A script for Exaile: bedtime-story.sh

As much as I like Exaile, it sadly lacks the option of turning a recording off after n minutes.

But, who needs a feature for the Exaile GUI when a script will suffice?

So, set your story up to play in the GUI, then use this:

bedtime-story.sh:

# turn the screen off
xset dpms force off

sleep $@ > /dev/null 2>&1

if [ $? = 1 ]
then
    # turn the screen on
    xset dpms force on
    echo "Fade out Exaile playback after a defined time, using the computer's volume control."
    echo ""
    echo "Usage: bedtime-story NUMBER[smh]..."
    echo ""
    echo "Each argument is a number followed by a unit."
    echo "The units are: s (seconds), m (minutes), h (hours)"
    echo "Example: bedtime-story 20m 10s"
    echo "The screen will be turned off, move the mouse or press a key to turn it back on."
fi

# grab current spot and volume, then gently fade and pause
c=$(exaile --current-position)
v=$(pactl list | grep Volume | cut -d ":" -f 3 | cut -d "%" -f 1 |\
 sed -n '1p' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
for((i=$v;i>=0;i--)) do
    sleep 1s
    pactl set-sink-volume 0 ${i}%
done
exaile --play-pause

# return volume to former setting
pactl set-sink-volume 0 ${v}%
echo "The current track was faded out beginning at $c."

Now I can go to sleep in style, whilst listening to the Internet's longest history podcasts. (in parts).

Saturday, 14 December 2013

The UNIX command line explained simply for UNIX experts

Seasoned UNIX users and developers of software often forget how mindbogglingly complex their creations are, because they use and work them every day, and --- it's just ever so obvious, right?

Why do newbies and even experienced users have such difficulty in grasping the timeless elegance and simplicity of a well-formed UNIX command line?

Well.  Allow me to put you, the expert, into the newbie's position for a moment :)

In the UK and Australia, there exists a particular fiendish form of crossword puzzle:  the cryptic crossword.

Here is a classic example of the type of mystifying clue such a puzzle offers:
15D Very sad unfinished story about rising smoke (8)
is a clue for TRAGICAL. This breaks down as follows:
  • 15D indicates the location and direction (down) of the solution in the grid
  • "Very sad" is the definition
  • "unfinished story" gives "tal" ("tale" with one letter missing; i.e., unfinished)
  • "rising smoke" gives "ragic" (a "cigar" is a smoke and this is a down clue so "rising" indicates that "cigar" should be written up the page; i.e., backwards)
  • "about" means that the letters of "tal" should be put either side of "ragic", giving "tragical"
  • "(8)" says that the answer is a single word of eight letters.
If the above maketh your mind go carroussel and gives your brain slight vertigo, you now know how most newbies and other mere mortals feel about the UNIX command line and the many cool options your software can be used with :-)

Example taken from The Guardian crossword of Aug 6 2002, set by "Shed", found in the Wikipedia explanation of Cryptic Crosswords.

Ps.: Brit and Aussie geeksters  who are crossword fiends will of course not be fazed at this attempt to demonstrate the users' head space, and I'll wager that at least one of them will now probably feel inspired to set a cryptic crossword with UNIX clues :-)

Monday, 30 September 2013

Sqlite compiler spam delenda est.


Because sqlite produces ~50000 extra letters of bumpf per compile that often obscures actually important compiler messages, I've not been as diligent as I should have been about reading compiler messages.  A lot the time I get lucky and it doesn't matter, but I also got caught out by that.

Here is how to get rid of all the noise and make your compiler output useful once again:

First we take a snapshot of the 'native' compiler messages that come with the trunk:

make 1>stdout.report 2>stderr.constant;
sort --unique stderr.constant > stderr.unique;
grep -v -F sqlite stderr.unique

This removes the sqlite warnings and shows you only the current warning messages that are actually ~/trunk related.

Any subsequent compiles that are started with the line below will use the generated stderr.unique file to filter output and remove every compiler message that is 'native' to the trunk, leaving just the compiler messages that pertain to your code:

make 2>&1 >stdout.report | tee stderr.report | grep -v -F -f stderr.unique >&2 2>/dev/null

You can also type this line when you invoke the emacs compile buffer and your C-x ` will continue to work.

Update:

Daniel Shahaf kindly mailed me his solution:

When I ran into this problem, I solved it differently: by building sqlite3 as a shared library and pointing configure to that.  Details  here:

https://svn.apache.org/repos/infra/infrastructure/buildbot/aegis/buildmaster/master1/projects/subversion.conf

# Built from the amalgamation with:
# s=/home/buildslave18/slave18/tools/sqlite; sudo rm -rf $s && sudo mkdir -p $s/include $s/lib && sudo cp sqlite3.h $s/include && sudo gcc -W -Wall -Wextra -Werror -fPIC -shared -o $s/lib/libsqlite3.so sqlite3.c -ldl -lpthread
# NOTE: this doesn't create a .la file for libtool, so libtool won't add this library to rpath of binaries compiled against it, so we have to set LD_LIBRARY_PATH below.
    '--with-sqlite=/home/buildslave18/slave18/tools/sqlite',

That approach is used by the warnings bot:
http://ci.apache.org/builders/svn-warnings

I suppose there's more than one way to skin a cat.

Cheers,

Daniel
(who can do './autogen.sh >/dev/null && ./configure -q && make -s' and
get no output and no warnings)

Friday, 20 September 2013

basename basically not so basic


It appears that GNU has three kinds of basename. 

They all do different things despite looking like the same thing, and usually it would make sense for something as basic as basename to be consistent.  However, no such luck, and I ended up suitably confused, and asked a friend to clue me up.  This is what he wrote:

"There are two different things called 'basename' here. There is 'locate --basename', and there is the GNU make function $(basename ...). They are both inspired by the command basename(1), which does yet a third conceptually similar thing (strip off the directory part and optionally a given suffix, if present), but other than that they have no connection to each other at all.

"Note that $(basename ...) is running the *GNU make function* 'basename': it is *not* doing the same thing that $(basename ...) would do in the shell and running the shell command 'basename'. If you wanted to do that in make, you'd use $(shell basename ...).

locate considers the basename of a file to be the last component of a filename. GNU make considers it to be *everything* in the filename before the first dot. When you consider their likely use cases, this makes sense: in make, you generally don't want to throw paths away when transforming names, because you're going to want to look those paths up again. If you wanted to strip pathnames too, you could say $(notdir $(basename ...))."

...so basically, basename is the same basic idea based on different bases.

In other, unrelated news, those who have managed to miss this video about 'Bohemian Gravity' below should watch it right now:




Thursday, 12 September 2013

I'm having a bash

I am currently working on my BRANCH_README file and I'm finding that my bash skills are seriously lacking :(

Sadly, I'm no longer a mud wizard, so the trusty old

   patch Gabriela barbarian_bash_skill +MAX
                                                             
spell is not longer an option and I will have to read a tutorial along with the bash reference instead.

UPDATE:  The above tuts are good, but this tutorial is amazing and has many examples, and in-depth explanations as to why and how things work.  
                                                          
However, it's sort of traditional that one has to 'bash with a bonecrushing sound':

  ... and this album is about as Heavy Metal as Cool Jazz can get.

Monday, 26 August 2013

DIY Quoting Tutorial Kit

Here's a link to a great UNIX quoting tutorial, and some lovely harp music to study with:


You supply the tea, and when the music is over and the cup is empty, you'll know how to quote just about anything and everything.  You can quote me on that.