A LaTeX Bibliography Hack

March 24, 2015

Yet another LaTeX hack! This time to insert text between the bibliography/reference header and the actual references. I’ve had, I admit, no really good reason to do this, as I might have added some text before the bibliography, but it made a lot more sense to include the paragraph there.

hack-bibliographie

Read the rest of this entry »


A (simple) LaTeX Example Environment

March 17, 2015

This week again, a little LaTeX. As you know, I’m putting the finishing touches to a manuscript I’ve been working on for a little bit more than a year now. Those “finishing touches” always start simple, then end up asking for quite a bit more LaTeX programming that I’d like.

latex-example-detail

This week, I worked quite a bit to repair my “example” environment that include example number, extra margin, and a different colored box around the text. This helps locate and distinguish examples from normal text. But my first version had little problems. Like equations centered not on the example text but still relative to the whole page. Bummer. Let’s see how I fixed all that.

Read the rest of this entry »


The Tosser

March 10, 2015

Here’s a LEGO dice-tossing machine I built.

The two complicated parts are the reduction gear train and the flaps that re-center the dice so that the machine can pick it up correctly each time.

The gear train is composed of several gear reducers, which are composed of a small gear driving a larger gear (thus many turns of the small, driving gear, are needed for the big one to make a complete rotation). Each large gear share its spindle with a small gear that drives the next stage. The gear box yields a 243:1 reduction (which is 3^5 to 1). Otherwise the motor spins too fast and just, well, eject the dice from the machine.

The flaps are used to funnel the dice back in the middle of the tray, where it can be picked up again.

*
* *

The next step would be to use OCR to read the dice value and see if, in the long run, the tosser is a strong number generator or if it is flawed in some way. Can’t really remember where I got the 16-sided dice, but there are some to be found online.


X marks the spot

March 3, 2015

I’m presently finishing a large text typeset in LaTeX. Of course, in many places I just put a note to “fill later” and moved on with the rest of the text. But now, I must hunt them down and fill the holes.

Good for me, I had the idea of writing a LaTeX command that not only marked the spot in the rendered page, like this:

fillme

…but also, by using the command itself, marked the spot in the source code itself. Otherwise, I’d have to find all the “fill me later” “add more” and whatnots.

The command itself is really not that complicated:

\usepackage{pifont}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\definecolor{bloodred}{HTML}{B00000}

\newcommand{\fillme}[1]{\textcolor{bloodred}{\smash{\ding{54}}}\message{Forgotten fillme on input line \the\inputlineno}} % 54 big fat X

The command takes an argument, which is ignored, but is quite convenient to leave the future you a message:

\fillme{blurb something about leibniz vs newton}

The command depends on the packages pifont for the dingbat and xcolor to define a nice dark red. The command itself does two things. One is to typeset a blood red X in the generated document so that it is conspicuous. The other is to output a message that can be parsed automagically by a script, making their eradication easier.


The Cutest Littlest Forkbomb

February 24, 2015

In one of his last tweets @levans posted the cutest Rust-lang fork bomb:

fn main(){std::thread::spawn(main);main()}

at 42 characters longs, which he sees like a sign. Excluding headers, you can do even shorter in C++:

main(){boost::thread x(main);main();}

It’s not really a terrifying forkbomb (as Linux, for e.g., kills everything after a while because processes run out of memory), and we could have done much worse with a process-level (rather than a thread-level) forkbomb:

main() { fork(); main(); }

This variant creates separate processes… none of which individualy can exhaust its memory! Don’t try this one on your main box (but it could be fun in a virtual machine).

bobomb


No post today

February 17, 2015

I’ve been insanely busy elsewhere lately, so no blog post today ¯\_(ツ)_/¯ .


Easy Timestamping with Bash

February 10, 2015

Here’s a quick Bash script to prefix lines read from standard input by a time stamp.

#!/usr/bin/env bash

while read line
do
    echo $(date "$@") "$line"
done

This script takes the same arguments as the traditional Unix date program. With no arguments, it prints some default-formatted date, but if you feel like it, you can pass it the same arguments as date. For example:

.../geolocalisation> cat /dev/ttyACM0 | ts.sh +"%H:%I:%M:%S.%N" | grep GPRMC | tee $(date | tr \  - | tr : - ).dat
15:03:42:57.355437828 $GPGGA,204226.000,4821.6737,N,06844.4790,W,1,08,1.2,-0.9,M,,,,00$GPRMC,204247.000,A,4821.6740,N,06844.4799,W,0.00,181.2,060215,,*2B
15:03:42:57.629415235 $GPRMC,204248.000,A,4821.6740,N,06844.4799,W,0.00,181.2,060215,,*24
15:03:42:57.881812555 $GPRMC,204249.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*2A
15:03:42:58.150091204 $GPRMC,204250.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*22
15:03:42:58.420285771 $GPRMC,204251.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*23
15:03:42:58.682492676 $GPRMC,204252.000,A,4821.6740,N,06844.4800,W,0.00,181.2,060215,,*20

So Let’s examine the script more closely. The $@ passed as argument to date is the series of all arguments passed to the script. Why is it enclosed in quotes? Because it preserves the structures of the arguments passed to the script for date. In the specific case of date it might not be necessary because of the nature of its arguments, but should you replace date with some other command, it may cause problems to remove the quotes. The $line is also enclosed in quotes because otherwise the script misbehaves: it would, for example, try to expand *.


Follow

Get every new post delivered to your Inbox.

Join 89 other followers