It's the perfect way of (gently) waking your brain up in the morning -- coffee is good, but a Tangram puzzle + coffee is superior. Also works great if you're stuck on a coding problem -- solve the tangram, and the solution to the other thingy just pops up in your mind a lot of the time.
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.
Colours make things easier to spot, especially if you have to look at a few metres of test output bumpf --- looking for something blue or pink is much quicker.
So, I made myself a little color.h file that lives in /usr/include/ where it is available anywhere I need some colour in my code.
You will probably notice the colour names --- I took the liberty of renaming 'green' to 'moss', 'bold green' to just 'green' and 'magenta' to 'purple' and so on. It's less to type, more descriptive, and, also functions as a small cheat map to understand the weird names the fashionistas in your life use to describe colour shades.
You can find the source for color.h here, note that the test code is present in the file in a comment, ready to be copied into a *.c file.
The claim was that this is the one case where goto isn't evil around minute 33:31 and that it performs better than switch. Well, does it? And if so, by how much?
So, there is a small difference, but it's really not that big a deal, unless you really are pressed for time and space.
The ever useful gcc manual has an entry about fun with local labels which will tell you more.
Still, building this by hand is tedious, even if emacs is your best friend. What if you have a huge array of a struct that maps variable A to variable B and also has an optional function pointer F?What you need is a 'fake_switch' generator, here is my version. It should be easily adjustable for your taste.
Goto it ;-)
Ps.: For extra fun, try this C to Assembler translator. I really like the hover feature they built, but another thing that would be useful is showing the size of the generated code.
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 )
The problem: You want your own malloc function, and there are gazillions of them in the code base you're working on. You could automate editing this lot, but littering the place with lots of custom xmallocs does not appeal, plus, there is are 3rd party libraries and you don't really want to mess with those.
#! /bin/bash # Compile a test file without those noisy -Wunused* flags, but # everything else that may be useful. # # Usage: compileCTest <name of your file without the '.c'> # give the executable an easy to spot and mass-delete friendly name executable="$1-exe" # remove the old executable if it exists if [ -e $executable ] then rm $executable; fi echo "" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "" # all flags from -Wall and -Wextra minus the -Wunused flags runGCC='gcc -g -std=c99 -Waddress -Warray-bounds -Wchar-subscripts -Wenum-compare -Wimplicit-int -Wimplicit-function-declaration -Wformat -Wmain -Wmaybe-uninitialized -Wmissing-braces -Wnonnull -Wparentheses -Wpointer-sign -Wreturn-type -Wsequence-point -Wsign-compare -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wvolatile-register-var -Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wsign-compare -Wtype-limits -Wuninitialized $1.c -o $1-exe -lm -lgmp' eval $runGCC # check that compile resulted in executable and if so, run it if [ -e $executable ] then # add a couple of dividing lines to make this easier to read echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="; ./$executable; echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="; fi
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."
One of my (very patient) mentors made the following very true observation about me:
By the way, designing features based on speculation is usually not a
good idea. (...) Maybe there's a bug report in our tracker requesting such
functionality? If not, perhaps you don't need to worry too much about that scenario.
I have a habit of assuming the worst case and then try to create something that (hopefully) solves for the entire range of problems/issues that might occur.
This sounds like it's a good thing, and sometimes it is, at other times, it isn't, because the sky is not about to fall.[1]
I've been thinking why that is so. and my best guess is that this probably a function of OO coding on the MUD, where anything and everything can cause surprises, because things interact whilst interactively interacting.
If you've ever replaced 20+ players lives, stats, xp points and equipment because your fun toy caused a chain reaction that you hadn't considered... you get extra careful after the umpteenth time ;-D
Of course I own a smartphone. Just that it's not a phone (I have an (ancient)(lightweight) Nokia for this task) but my Apple only does 3 things that are useful to me:
1) work as a timer and reminder
2) enable me to take cooking recipes I find on the web into my kitchen
3) play the odd mp3 over the small speaker as a bedtime story
Other than that, the screen is too small to comfortably read or do anything on, and whilst I could get a bigger model, the small one I have is already too heavy to lug about as is, and, a larger screen would still be too small.
Don't you get bored just sitting around, say, waiting for Godot or on other occasions?
Nope, because my brain is a far more useful and interesting device than a smartphone, and if I really am in idle input mode, I have a tiny little Samsung U5 so I can listen to audio books. This little toy weighs 28 grams and I can tuck it anywhere into my clothes.
Also, I quite like just sitting somewhere and looking at the world pass by, giving my mind the free run of my brain to grep for interesting things in my thoughts I've been unaware of so far.
If you do not have idle time for your brain to run riot in, it kills your creativity -- 'boredom' is the best inspiration because your mind hates a void and will find a way of entertaining you with ideas, the moment you give your mind time and space to talk to you.
After nearly losing all my work yesterday, I've made this little script to run in the Emacs compile buffer before the make command. This runs svn diff every time I compile and puts the result into a separate directory.
"Your BRANCH-README file
<http://svn.apache.org/repos/asf/subversion/branches/invoke-diff-cmd-feature/BRANCH-README>
is a fantastic window into the branch, much more detailed and
helpful than the rest of us ever write. I can easily see exactly what
the whole feature does, how it's structured, and what your plans are,
without having been paying close attention. I'm mentioning this mainly
so anybody else contemplating taking a look at this knows this is a good
place to start reading. And I'm pleased to see you have taken care to
adhere to our coding style.
"
It's the most wonderful compliment I've heard in years :)
{And, to be honest, writing this BRANCH-README helped me a lot in getting things done and keep me focused on what I was (and am) trying to do. It was danielsh who suggested that I should write one (ironically I initially omitted it, despite fixing a part of the hacking guide entry for this most excellent advice.)}
Here is how to use the svn diff output within the emacs compile buffer to generate a handy list of files with line numbers that you can click on to visit every bit of code you've changed:
#!/bin/sh ${SVN_INSTALLATION?"Please set the environment variable SVN_INSTALLATION."} SVN=$SVN_INSTALLATION BRANCH_DIR=`pwd` tmp=`$SVN info 2>&1 | grep SVN_ERR_WC_NOT_WORKING_COPY` if [ -n "$tmp" ]; then echo "Error: The branch directory does not contain a SVN repository." >&2; exit; fi TRUNK_DIR=$1 REL_DIR=$2 if [ -z "$TRUNK_DIR" ]; then echo "Usage: mergeBranch <trunk directory>" >&2; exit; fi if [ ! -d "$TRUNK_DIR" ]; then echo "Error: Trunk directory not found." >&2; exit; fi cd $TRUNK_DIR tmp='$SVN info 2>&1 | grep SVN_ERR_WC_NOT_WORKING_COPY' if [ -z "$tmp" ]; then echo "Error: The trunk directory does not contain a SVN repository." 1>&2; cd $BRANCH_DIR exit; fi cd $TRUNK_DIR; $SVN up tmp=`$SVN info | grep "Last Changed Rev:"` TRUNK=${tmp##*: } cd $BRANCH_DIR tmp=`$SVN info | grep "Last Changed Rev:"` BRANCH=${tmp##*: } $SVN up WHAT=${BRANCH_DIR##*/} echo "On the $WHAT branch: trunk revision $TRUNK merged into branch revision $BRANCH." > log.mesg $SVN merge $REL_DIR
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:
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:
# 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',
Whilst doing the long overdue merge of trunk into my invoke-diff-cmd branch, I spotted a deprecation warning that looked like a minor oversight, and so, I fixed it, svn compiled, the tests passed and ... the patch turned out to be a no-can-do, because APR_ARRAY_PUSH doesn't care what type you stuff in there.
I thought it did, because of this: #define APR_ARRAY_PUSH(ary,type) (*((type *)apr_array_push(ary)))
which *looks* like it's type-safe at least if you don't know what you're really looking at (and if you haven't bothered to check the underlying code to see what it actually does). It of course does no such thing -- so, what does this trick that does seemingly nothing actually do?
[19:32] <breser> gbb: The reason it takes a type is to avoid warnings. The apr_array_push() function returns a void *. Technically there's no issue with putting any pointer in a void pointer, however some compilers will warn you about that since you may not be doing it intentionally.
[19:33] <breser> gbb: The array code doesn't care what the pointer is to, it's up to the user of APR Arrays to keep their types straight.
[19:34] <breser> gbb: In this case the fact that the array code is taking a type (and casting) is hiding the errors/warnings you would have otherwise seen.
[20:30] <Bert> breser, gbb: Apr arrays can be of different kinds than just pointers. In some cases we have arrays of specific struct kinds (e.g. for property changes in the diff handling)
Thank you Ben and Bert, it certainly did clear things up, and made me look up the 'long answer' --- the very short answer of course is that C isn't C++, and so doesn't have type-safe templates. Caveat coder!