No Disconnect

Things I’d rather not forget

How SVG units work

leave a comment »

From the specification:

“1pt” equals “1.25px” (and therefore 1.25 user units)
“1pc” equals “15px” (and therefore 15 user units)
“1mm” would be “3.543307px” (3.543307 user units)
“1cm” equals “35.43307px” (and therefore 35.43307 user units)
“1in” equals “90px” (and therefore 90 user units)

Written by nodisconnect

January 3, 2012 at 10:52 pm

Posted in Uncategorized

Linux remove directory and all contents

leave a comment »

rm -rf NameOfTheDirectory

Written by nodisconnect

January 2, 2012 at 3:04 am

Posted in Programming

What to do with all the GTK+ library files in Win32

leave a comment »

Lots of files are helpfully provided here: http://www.gtk.org/download/win32.php

Not bad Win32 support for a GPL, but as is typical, they don’t tell you what to do with them. :-)

What you do is open the zip files, and merge them with the folders in your MinGW directory. The best way I found to do that is to move the zip file to my mingw directory (in my case, C:\Qt\4.7.1\mingw), and then use Windows’ “Extract all…” feature, which will offer to merge the directories automatically.

One more wrinkle: the “Dev” versions are necessary to build code using the libraries; the “Run-time” versions are necessary to actually execute the program. Both need to be installed as described above.

Written by nodisconnect

January 1, 2012 at 11:29 pm

Posted in C/C++, Programming

The actual HTML Tidy documentation

leave a comment »

For whatever reason there are a ton of pages purporting to document HTML Tidy. This one seems to be the real one:

http://tidy.sourceforge.net/docs/tidy_man.html

Written by nodisconnect

December 28, 2011 at 2:29 am

Posted in XML & Friends

Insert characters around characters in XeLaTeX (for RTL languages)

leave a comment »

In typesetting RTL documents in XeLaTeX, I have found that characters such as colons or parentheses don’t set properly—adjacent numbers disappear, etc. The code below makes TeX place empty hbox’s around each colon in a document. No further references to macros are necessary.

 

\def\colon{:}
\catcode`:=\active
\def:{\hbox{}\colon\hbox{}}

Written by nodisconnect

December 3, 2011 at 3:36 am

Posted in TeX/LaTeX

Get the variables/attributes/members of an object

leave a comment »

names(myObject);

Written by nodisconnect

July 15, 2011 at 8:00 am

Posted in R

xsltproc (XSL transformations)

leave a comment »

xsltproc is the best (most efficient) way I’ve found to do XSL transformations. Some of the DLL dependencies have to be from libraries downloaded at the xsltproc web site (or rather, the web site of the associated libraries).

xsltproc ocm.xsl newOcm.xml > result.txt

 

xsltproc --param which-page 1 -o output.svg xml2svg.xsl nasim.xml

 

xsltproc --param which-page "hello world" -o output.svg xml2svg.xsl nasim.xml

Written by nodisconnect

June 20, 2011 at 3:39 am

Posted in XML & Friends

C++ object/pointer construction/deconstruction

leave a comment »

#include <iostream>

using namespace std;

class A
{
public:
 char label;
 A()
 {
 label = 'X';
 }
 A(char l)
 {
 label = l;
 cout << "Constructing " << label << endl;
 }
 ~A()
 {
 cout << "Deconstructing " << label << endl;
 }
};

int main()
{
 A a('a');
 A *b;
 A *c = new A('c');
 A *d = new A('d');
 delete d;

 return 0;
}

Output:

Constructing a
Constructing c
Constructing d
Deconstructing d
Deconstructing a

Written by nodisconnect

March 1, 2011 at 10:58 pm

Posted in C/C++, Programming

Getting coefficients and p-values from an R lm class

leave a comment »

dependent <- runif(100);
independent <- runif(100);
tmp<-lm(dependent ~ independent);
summary(tmp);
correlation <- tmp$coeff['independent'];
intercept <- tmp$coeff['(Intercept)'];
f <- summary(tmp)$fstatistic;
p_value <- 1-pf(f['value'], f['numdf'], f['dendf'])

Written by nodisconnect

January 25, 2011 at 10:04 pm

Posted in R

Principal component analysis in Octave

leave a comment »

% create sample data
matrix = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
matrix = matrix.^2;

matrix = center(matrix); % subtract column means
cv = cov(matrix); % calculate covariance
[v, lambda] = eig(cv); % compute eigenvectors and eigenvalues
[sorteigen, order] = sort(diag(lambda),'descend'); % sort the eigenvalues
v = v(:,order); % sort the eigenvectors the same way

data = [1 2 3; 4 5 6; 7 8 9; 10 11 12]; % a new dataset
means = mean(data); % calculate the column means
data = center(data); % subtract the means
transdata = v' * data'; % project into the new eigenspace
reconstituted = (v*transdata + repmat(means,size(data,1),1)')'; % project it back the other way, and add the means back

Written by nodisconnect

January 25, 2011 at 2:27 am

Posted in Octave/Matlab

Follow

Get every new post delivered to your Inbox.