12 July 2012

207. apt-get, apt-cacher-ng and hash sum mismatch

Update: Another day and we're back to the same crap with Hash sum mismatches. It's getting old...however, I'm beginning to suspect it's not the mirror, but my apt-cacher-ng.

I was getting a bit peeved with getting intermittent messages about 'hash sum mismatch' etc. when trying to do sudo apt-get update

Ign http://dl.google.com stable/main Translation-en                                                                                                                                                                                         
Fetched 17.1 MB in 9s (1,736 kB/s)                                                                                                                                                                                                          
W: Failed to fetch bzip2:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_main_binary-amd64_Packages  Hash Sum mismatch

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_contrib_binary-amd64_Packages  Hash Sum mismatch

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_non-free_binary-amd64_Packages  Hash Sum mismatch

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_contrib_i18n_Translation-en  Hash Sum mismatch

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_main_i18n_Translation-en  Hash Sum mismatch

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_non-free_i18n_Translation-en  Hash Sum mismatch

E: Some index files failed to download. They have been ignored, or old ones used instead.


So I took action:
sudo rm -rf /var/cache/apt-cacher-ng/*

But then
sudo apt-get update    
Get:1 http://192.168.1.1 testing InRelease [190 kB]
Err http://192.168.1.1 testing InRelease                                                                                                                        
Ign http://192.168.1.1 stable InRelease                                                                                                                         
Get:2 http://192.168.1.1 stable Release.gpg [1,672 B]                                                                                    
..
Fetched 7,004 kB in 7s (965 kB/s)                                                                                                                                                                                                           
Reading package lists... Done
W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://192.168.1.1 testing InRelease: File /var/lib/apt/lists/partial/192.168.1.1:3142_ftp.iinet.net.au_debian_debian_dists_testing_InRelease doesn't start with a clearsigned message

W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/InRelease  

so I

sudo apt-get install debian-keyring

which didn't solve anything

Solution:
Edit you /etc/apt/sources.list and replace all instances of testing with wheezy, e.g.

deb http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/ wheezy main contrib non-free
deb http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/ stable main contrib non-free

I don't know if this has to do with the transition towards freezing wheezy, but basically, if you're having problems like that, have a look at what's actually on the mirror you're using. In my case I had a look at ftp://ftp.iinet.net.au/debian/debian/dists/ and found no 'testing' directory.


It also took care of these related messages on a different node:

Fetched 7,493 kB in 8s (885 kB/s)
W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/contrib/binary-amd64/PackagesIndex  MD5Sum mismatch

W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/contrib/i18n/Translation-enIndex  MD5Sum mismatch

W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/non-free/binary-amd64/PackagesIndex  MD5Sum mismatch

W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/non-free/i18n/Translation-enIndex  MD5Sum mismatch

W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/main/i18n/Translation-enIndex  MD5Sum mismatch

W: Failed to fetch http://192.168.1.1:3142/ftp.iinet.net.au/debian/debian/dists/testing/main/binary-amd64/PackagesIndex  MD5Sum mismatch

206. Chrome, cookies and incessant spying

With age and added responsibilities I'm becoming grumpier and grumpier.

I read lxer.com everyday since it provides a good aggregation of linux-related news. On clicking on this link to h-online I was shown a pop-up in the top left corner letting me know that h-online uses cookies, and by clicking close my consent to be tracked is assumed. A link was given to a page where I could opt out, and another link to etracker was provided on that page. Clicking on that and eventually getting past the captcha told me that etracker will no longer track my browser (so I have to do it for chrome, chromium, and iceweasel? And on every one of my six computers?)

I signed up for my first dial-up internet connection in 1996, and as far as I can remember cookies were heavily discussed already back then. However -- and again this is as far as I can remember -- accepting cookies wasn't necessary since not every website + their mum was using them to track you. 

As far as I can see there are a few reasons why websites want to set first or third party cookies:
* Ads. Targeted ads.
* Information. Which is then sold to companies tailoring ads.
* Automatic log-in and customisations
* Because everyone else is doing it


I've cleared my cache, but I saw cookies from the Swedish ministry of foreign affairs, among others. I find it difficult to imagine a legitimate reason for them to set a local cookie on my computer. I don't think there is any evil intent behind it -- instead it's probably a case of 'why not?'.


It's easy enough to set your browser to block all cookies or to automatically delete them on closing your browser. Some browsers allow you to accept cookies on a site/provider basis. This easily leads to you having to click pop-up after pop-up after pop-up...

The ideal case -- from the point of the user -- is one where you block all cookies and add exceptions for sites that YOU deem have legitimate reasons to set cookies and where YOU benefit from having cookies set.

A little experiment. Try disabling cookies completely, and then log-in to your blogger or gmail account. Try adding an exception for google servers only, then log in to blogger -- you get stuck in a nice little loop which only gets broken if you add an exception for blogger.

In fact, I can't even do much on the university network without allowing cookies -- the university wants to set cookies in order to allow me to do just about anything.

Anyway, after that rant, here's how you might want to manage your cookies in google chrome:
Got to settings in google chrome and type in cookies

Click on Content Settings.
Check:
* Block sites from settings any data
* Block third party cookies and site data
Then click on Manage Exceptions 

 Add sites YOU feel should have the right to add cookies.
With google and blogger you have little choice: in order to use those sites you need to enable cookies.
Note that wildcards are added using [*.]


You may also want to clear you cache to get rid of cookies which have already been set.
Continuously add exceptions for sites which you want to grant the ability to set cookies. 

You can also add sites by clicking on the cookie icon to the right of the URL field in your browser:

Take a look at what cookies are set every now and again.

If you find that you have plenty of cookies like these:

it's likely because you have the Google Opt Outs enabled:




10 July 2012

205. Debian, TeXLive and style files: making lecture slides

Because I keep forgetting...(my blog serves as a public notebook). I don't make any presumptions about this being terribly new or relevant to a lot of people.

This post expanded into something quite different from what was indicated by the title:

Here's the short version:
kpsewhich -var-value=TEXMFHOME
$HOME/texmf
ls $HOME/texmf
ls: cannot access /home/me/texmf: No such file or directory
mkdir ~/texmf/tex/latex -p

Copy your style files e.g.
cp lecturestyles/ -R ~/texmf/tex/latex

(sudo) texhash

And here goes the long version:

I hate powerpoint presentations --- even if they are made with latex (time to make it a generic trademark?) but the university I'm working at considers blackboards too old-fashioned. Apparently the maths and physics departments are still fighting the good fight, but my department has rolled over. Why do we let people who don't teach decide how we do things? Anyway...

For my lecturs, slides, seminar talks etc. I'm using a fairly heavily edited version of this
http://robjhyndman.com/researchtips/latex-templates-for-monash/
for making slides. It's served me well for giving seminar talks etc. I'm currently putting together a new course* and it's now becoming more important than ever to make sure I organise my material already from the outset.

So, a few things to do:
1. Organise everything neatly in folders:
main.tex

/lectures/silicon.tex
/lectures/aluminium.tex

images/aluminium/
images/algorithms/opa

etc.

Beware: when you include images in silicon.tex but call silicon.tex via main.tex, the paths are relative to main.tex, i.e. it's not ../images/aluminium/ore.eps but images/aluminium/ore.eps.

2. Finally move the style files from the local folder (i.e. where the tex file is) to the destination indicated by TEXMFHOME variable:


kpsewhich -var-value=TEXMFHOME
/home/me/texmf
ls $HOME/texmf
ls: cannot access /home/me/texmf: No such file or directory
mkdir ~/texmf/tex/latex -p

Copy your style files e.g.
cp lecturestyles/ -R ~/texmf/tex/latex/

(sudo) texhash 

3. Make liberal use of \include{} in latex
Basically -- you have a document with the preamble

\documentclass[14pt]{beamer}
\usepackage[version=3]{mhchem}
\usepackage{array}
\usepackage{color}
\usetheme{styles/Hytex}
 \def\biz{\begin{itemize}[<+-| alert@+>]}
 \def\eiz{\end{itemize}}
 \def\ben{\begin{enumerate}[<+-| alert@+>]}
 \def\een{\end{enumerate}}

\title{Chemistry 3456}
\author{Verahill}
\date{}

\begin{document}
\include{lectures/introduction}
\include{lectures/silicon}
\include{lectures/phosphorous}
\include{lectures/aluminium}
\end{document}

And then you create individual files for each lecture or topic e.g. silicon.tex:

\title{Silicon: spines, shells and minerals}
\begin{frame}
 \titlepage
 \centerline{Department of Chemistry}
 \centerline{\includegraphics[width=8cm]{styles/myunilogo}}
 \centerline{\small\color[rgb]{0.01,0.33,0.58}}
\end{frame}

\section{Silicon}
\begin{frame}
Today's lecture will cover:
biz
\item Bouncy balls
\item Froth reductors
eiz
\end{frame}

without preambles or anything of that sort.

It's still a bit annoying that you can't set the location of the aux, nav, log etc. files in each .tex document since the clutter offends my eyes. But hey, there's a limit even to my grumpiness.

4. \usepackage{}
Try looking for chemistry related packages which are installed on your system
find /usr/share/texlive/texmf-dist/tex/latex/ -name "*.sty"|grep [cC]hem

The ones which show up on my system are:
achemso, mychemistry, chemstyle, chemcompounds, mhchem, chemmacros, chemarrow and chemfig

mhchem is most likely the most useful one:
\usepackage[version=3]{mhchem}
You can either do
\ce{OH-}+\ce{[B(OH)3} $\rightarrow$ \ce{[B(OH)4-}or more elegantly:\begin{reaction}
OH- + B(OH)3 -> B(OH)4-
\end{reaction}
SIunits are good too:
\usepackage{SIunits}
The bond length is 1.1 \angstrom{} at 298\kelvin{} (25 \celsius{})
Chemfig looks very promising for a 2D chemistry drawing package and uses tikz, but it has a fairly steep learning curve (in the sense that you need to familiarise yourself with most use cases before you can do anything - it doesn't necessarily take very long):

\chemfig{C(-[2]H)(-[4]H)(-[6]H)-C(-[2]H)(-[6]H)-H}
draws ethane. The 2, 4, 6 are angles in multiples of 45 degrees. So, there are H at 90, 180 and 360  relative to the first carbon. 0 degrees is parallel to the horizontal, and angles increase as in a normal coordinate system (i.e. counter-clockwise).
In addition, you can do Lewis dot structures:
\chemfig{B(-[3]\lewis{420,Cl})(-[5]\lewis{460,Cl})-\lewis{260,Cl}
The 420 means bar to the left (0), top (2) and left (4). 260 means bar left, bottom and top. There's a lot to learn though...

Lastly, e.g.
\chemfig{*6(-=-=-=)}
draws benzene. The 6 indicates a hexagon and the -=-= the sequence of bonds.


5. Dia for flowcharts and cycles
I tried using tikz to make pretty, native flowcharts and cycling diagrammes, but it was too much work and too hard for lecture slides (I might revisit it for articles)
Instead, the dia package in debian make it easy to quickly make up .eps flowcharts

6. Use inkscape to turn png into eps
A lot of programmes can create eps files from raster formatted image files. However, most of them do a very poor job.

Instead I like using inkscape and have a .sh file for it:
inkscape --verb FileSave --verb FileClose --export-eps=$1.eps $1.png

7. BKChem for more difficult schemes
8. GDIS/povray for nice 3D structures.

9. MOdiagram for MO diagrams. Awesome BUT enabling labels leads to catastrophic failure:
"! Font LGR/cmss/m/n/12=gsmn1200 at 12.0pt not loadable: Metric (TFM) file not found."

You need to install cbfonts which is supposed to be included in texlive (I think). But it seems that some files are missing. Download cbfonts.zip from http://www.ctan.org/tex-archive/fonts/greek/cbfonts. Assuming you downloaded in ~/Downloads.
mv ~/Downloads/cbfonts.zip ~/tmp
cd ~/tmp
unzip cbfonts.zip
cd cbfonts/
sudo cp fonts/* -R /usr/share/texmf/fonts/ 

sudo update-updmap

sudo texhash && sudo updmap-sys
*to all my former lecturers: I am so, so, so truly sorry for not appreciating more how 1) much effort is involved in putting together a course (even a badly prepared one) and 2) as an undergraduate I didn't acknowledge that teaching isn't your main job.