Snippets
“Snippet” is a programming term for a small region of re-usable source code or text.
Get easy statistics for C++ STL classes (or your own)
The files in stats.tar.gz (2.29 KiB) allow you to do quick-and dirty descriptive statistics, especially together with boost lambda:
2 #include <stats.hpp>
3
4 ExactDescriptiveStatistics floatstat ("Float : ");
5
6 for (float f=0.f; f<10.f; f++)
7 floatstat+=f;
8
9 ExactDescriptiveStatistics intstat ("Ints : ", intvec.begin(), intvec.end());
10
11 ExactDescriptiveStatistics tstat ("Thresholds : ");
12 tstat.notify(vec.begin(),vec.end(),bind(&Neuron::mThreshold,_1));
13
14 cout << tstat << endl << intstat << floatstat << endl;
15
Draw boxplots for columns in datafiles.
The perl-script does the necessary statistics and generates a box plot. It is configured using INI-style files.
boxplot2.pl (4.77 KiB)
Vary Parameters in .ini-Files
It is quite easy to write a program in any language which is configurable via .ini-files like this:
param1 = 1
param2 = true
param3 = 1
If you now want to test this program for all combinations of parameters, you run into a problem: Where do you implement the loop over all parameter combinations? The script varyParams2.pl (8.50 KiB) is an elegant way out: You write one more .ini-file that tells it what to vary where and it will run the whole experiment for you. The documentation is embedded, you can also read it online.
Convert Phone Numbers to Words
Words are easier to remember than numbers! phony.pl (1.04 KiB) takes a phone number and a dictionary as its input and tries to find words that you can enter on your phone “instead” of the number.
Deutsch -> Sächsisch Konvertierer
2
3 # #!/usr/bin/perl -wnp
4
5
6 while(<DATA>){
7 print join ' ', map {
8 ($pre,$_,$post) = m/^([^\w]*)(\w.*?\w)([^\w].*)?$/;
9 $pre ||= "";
10 $post ||= "";
11 s/ebe/eh/ig;
12 s/st/schd/ig;
13 s/sp/schb/ig;
14
15 # phonetics
16 s/t/d/ig;
17 s/ck/gg/ig;
18 s/k/g/ig;
19 s/p/b/ig;
20 s/ei/ee/ig;
21 s/ö/ee/ig;
22 s/er$/or/ig;
23 s/ig/sch/ig;
24 s/au/u/ig;
25 s/nd$/n/ig unless /Mund/i;
26 s/st$/s/ig;
27 s/en$/n/ig;
28 s/a/o/ig;
29 $pre . $_ . $post
30 } split /\s+/;
31
32 }
33
34 __DATA__
35
36 angesichts der aktuellen Ereignisse finde ich es nicht satirisch, sonders
37 vielmehr geschmacklos ein Amokformular zum Download anzubieten. Es gibt so
38 viele TRittbrettfahrer, die nur auf so etwas warten. Ich wurde auf den Link in
39 einer Internetplattform, in der sich überwiegend Schüler ab ca 11 Jahren
40 bewegen aufmerksam. Ich appeliere an Ihre Verantwortung gegenüber der jungen
41 Generation dieses Dokument sofort zu entfernen. Das hat leider mit Satire
42 nichts mehr zu tun! Mehr Sensibilität der Medien würde ich mir wenigstens in
43 der Weihnachtszeit wünschen.
Webgen Syntax Highlighter Plugin Using Vim Editor
This site is generated using webgen. Webgen has limited support for syntax highlighting, as it uses the ruby coderay library. Coderay supports only a few languages. The following plugin for webgen uses the vim editor to highlight code in basically any language. It caches its output and only runs vim if something changed.
Install:- Install the
yankcode.vim plugin from
vim.org (just drop the file in your
.vim/plugin
directory) - Drop hilight.rb (2.49 KiB) “plugin” directory of your homepage.
- Add something like this to default.css:
1 .vimblock { margin-left: 1.5em;
2 padding-left: 5px;
3 border: 1px dotted #ccc;
4 border-left: 5px solid #ccc;
5 color: #000000;
6 background-color: #f0f0f0;}
7 .lnr { color: #999999; font-weight: bold; }
8 .PreProc { color: #800090; background-color: #f0f0f0; }
9 .Normal { color: #000000; background-color: #f0f0f0; }
10 .Error { color: #ee2c2c; background-color: #f0f0f0; }
11 .Identifier { color: #007080; background-color: #f0f0f0; }
12 .Type { color: #912f11; background-color: #f0f0f0; font-weight: bold; }
13 .Constant { color: #077807; background-color: #f0f0f0; }
14 .Comment { color: #786000; background-color: #f0f0f0; }
15 .Statement { color: #1f3f81; background-color: #f0f0f0; font-weight: bold; }
-
{hilight: {filename: test.cpp } }
no retabbing, let vim determine language -
{hilight: {filename: test.pl, lang: prolog } }
no retabbing, fix language -
{hilight: {filename: test.cpp, retab: true } }
retab file -
{hilight: {filename: test.cpp, number: false } }
no line numbering