Posts Tagged ‘fugitive’


Sunday, August 28th, 2011

Imagemagick, again

There has been quite a lot of hacking using imagemagick this past week, all of it for FSCONS use.

My first hack was to create an image for use in the MyConf site, to visually mark up passed timeslots as, well… passed.

The idea I had was to set a background on that html element which would have “Session has ended” written diagonally from the lower left corner to the upper right.

Greg convinced me that there must be better ways to mark this up which would at the same time not interfer with the readability of those sessions, and we ended up going another way, but this is how to create images with diagonal text anyway:

$ convert -size 400x200 xc:none -fill red -pointsize 40 -gravity center -draw "rotate 337.5 text 0,0 'Session has ended'" tmp.png

This will create a 400px wide by 200px high image, with a transparent background and red text, rotated to lay diagonally across the image, beginning in the southwest corner of the image and ending in the northeast.

The next day Rikard had an idea about using an FSCONS crowd image as background for another image, and have parts of the crowd “bleed through” the overlaying image.

This is of course something one can do in GIMP, iff you have learned how to. Rikard struggled with that, got help from Jonas, but ultimately the result wasn’t good, and he’d have to do it all over again, at which point Jonas had left for the day and he didn’t remember what had been done.

Which got me thinking “this must be doable in imagemagick, and repeatable (i.e. a shell script)”. Of course it was.

It is a two-step process, first you’ll need to prepare the overlaying image, by making parts of it transparent, enabling the background image to bleed through. This is done with:

$ convert overlaying-image.png -transparent black new-image.png

In the above example, the color black in “overlaying-image.png” will be made transparent, and the output saved into “new-image.png”.

For my tests, as I only needed a background image, and as anything would suffice, I had imagemagick create one for me:

$ convert -size 525x525 xc:blue bg.png

This will create an 525*525 pixel image with a blue background color.

With this done, all we need do is to merge the two images (“new-image.png” and “background-image.png”) together:

$ composite -gravity center new-image.png background-image.png resulting-image.png

One little gotcha with this command above: I haven’t tried what happens when I use two differently sized images. I am assuming that things will get cropped.

Media Queries

This Thursday I was introduced to Media Queries, a rather cool technique for having CSS determine (well, I suppose it really is the web browser which does all the work, while CSS is just the container for the rules) which styles to apply, depending on certain browser attributes (such as current width of the window, etc.)

Greg has implemented this in MyConf and it is pretty cool when you shrink your browser window down to about 200 pixels or so, and the page transforms before your eyes.

graphvis and neato

On thing which have bothered me about neato for a long time is that I could never find a way to have the nodes not overlap in the generated image.

There is syntax for how to space out nodes inside the graphviz grammar, and it works… sortof, but I actually found a better way to go about it now.

$ neato -Tpng -o resulting-file.png -Goverlap=false


When I updated the WP Stats plugin this Friday I was “greeted” with the message that I wouldn’t receive any further updates to the stats plugin and that I should get Jetpack instead.

It promised to be great and awesome and connect my blog to the “WP cloud” (whatever that is), but instead of filling me with optimism and making me look forward to that change, all that message managed to do was make me think “ok, I wonder how long before they’re gonna start charging for access to all this Jetpack functionality”.

Automattic is of course free to do so if they feel like it, but I can’t help but feel that it is ass-backwards to have the self-hosted platform, and then try to tie it into that “WP cloud” (whatever that is, again they leave me with more questions than answers)…

The funny thing is that WP Stats was one of the features that I really liked, and which made me hesitant to move somewhere else.

So thanks Automattic… but no thanks. Time to speed up the plans for migrating to fugitive…


Sunday, July 10th, 2011

Imagemagick hackery

This post outlines how to create an image containing text, using imagemagick. The comment made by Severin improved upon the original snippet by cropping the image to just fit around the text.

One could use this in a script if you just set the following variables: width, height, fontsize, text and filename. I could have added another variable for font, but that would have made the example code below less informative.

convert -size ${width?}x${height?} xc:transparent -font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf -fill black -pointsize ${fontsize?} -draw "text 0,${fontsize?} '${text?}'" -trim +repage ${filename?}.png

LaTeX and variables

One of the neatest things about LaTeX (except for the automagic table of contents generation, ease of use when it comes to references, and never having to worry much about typesetting) is that it really is a markup language. A markup language where you can define your own “macros” (commands as they are called in LaTeX). And these commands can be just as simple or complex as you have the skill to make them.

So for instance, if you are writing something in LaTeX, and you find that you have to write the same thing over and over again, you could define a new command which prints that for you wherever you call the command (this of course relies on that what you are writing many times is longer than the name you give your command, otherwise it wouldn’t make much sense. Unless of course this something you are repeating, may be subject to change later, and you don’t look forward to doing a search / replace across the entirety of the document(s).

I remember that our group used this during a semester at ITU, but then I “rediscovered” it this Monday as I embarked on a small writing project, being unsure if I liked the names I’d given my characters.

So now I have a “characters.tex” file, which just defines a couple of commands. These commands, in turn, do little more than return the name I have currently given the character. characters.tex is then imported into the main file (“novel.tex“) and whenever I need to call a character by name, I just use the command I defined for that character.

This question over at helped me with an answer:


I.e. We call the command \newcommand which takes two arguments, whereof the first is the name of the new command (in this case \protagonist1) and a command body, what the new command should do, which, in this case simply is to output the string “Tony”.

Ok, protagonist1 sounds kindof silly, and perhaps I should have named the command nightclubOwnerFname instead, but that would have been a fingerfull to type.

What you take away from all this is that if I ever decide to rename Tony to… iunno, Mark? I will only have to change it in one place, the characters.tex file.

To include a file in LaTeX you use:


Why the “.tex” from “characters.tex” should be omitted in the input command I have no idea about, but that’s how I learnt it, and it works. One day I should really sit down and figure that one out.

Finally, to use the command inside your text you just write your stuff, but instead of writing the name you call the command:

She looked at \protagonist1{} in disbelief.

That’s pretty much all there is to it. Ain’t LaTeX neat?

Creating diffs in git

I started looking into fugitive but hit a brick wall smack dab in the beginning of the adventure as I’m running Arch, and its version of git was just slightly newer than that of p4bl0.

Once I got fugitive running, I wanted to get it to handle markdown (i.e. parse the markdown marked up as a part of the process of generating the published html), which had some unintended consequences for the <title> tag (i.e. markdown had already parsed the first line in the file, which is used as the post title) and this resulted in <title><p>my post title here</p></title>… that ain’t so good ;)

The upside to it was that I got to do a little digging around in code (which I need to get better at anyway) and I ended up solving that little problem (but that introduced a bug (yes, I suck, should’ve tested more first) but I have submitted another patch which should undo all my stupidity and make it right. This time I have done more testing ;))

BUT, it also meant that I needed to generate a diff that p4bl0 could use to patch fugitive. This blog post gave me all I needed to know, i.e.:

$ git diff --no-prefix > patchfile

Automatically mounting removable media in Arch

Although it can be reckless to automount stuff (because you never know where that USB stick has been ;)) it can be nice (comfortable) to have it all done for you, and that’s where autofs can help you.


Update: fixed silly typo, thank you mina86