Archive for April, 2011

Mac OS X 10.6 VPN configuration error after wrong password

Wednesday, April 27th, 2011

The built-in VPN client in mac os x 10.6 annoyingly won’t remember passwords. I have to type it in every time I connect. What’s worse is that if I mistype it some how ruins the VPN client so that I can reconnect. When I try I don’t even make it to the password prompt. I just get:


A configuration error occured. Verify your settings and try reconnecting

I manage to restart the VPN client by issuing this in a Terminal:


sudo launchctl stop com.apple.racoon
sudo launchctl start com.apple.racoon

After that when I try, I get to the password prompt and I’m able to reconnect.

Similar idea here

List all unique fields and functions used by C++ object pointer in many files

Thursday, April 21st, 2011

Here’s a little bash one liner to find all fields and functions used by a C++ object pointer in all files of the current directory. The object I’m looking for always has a name ending in “mesh”, which makes this a bit easier:


grep -ho "mesh->.*" * | sed -e "s/.*mesh->\([^(\[,\.]*\).*$/\1/g" | uniq

For me this prints exactly what I wanted:


ComputeShortestPathInTetVertices
Copy
FindClosestTetVertex
IsTetMesh
surface_to_tet_map
tet_neighbors
tet_vertices
tet_vertices for volume problem
tetrahedra

Ignore nytimes paywall with simple client-side javascript, or applescript

Thursday, April 21st, 2011

Today was my first experience with the New York Times paywall. It manifested as an html overlay on top of the article I wanted to read. The article seemed to have fully loaded which made me think that if I could just get rid of the overlay I’d be able to read it.

This turned out to be the exactly case. I just zapped the div containing the overly (properly labeled id='overlay' and restored the overflow of the main page (to get scrolling back).

ignore nytimes paywall

This is easily accomplished with three lines of client side javascript:


document.getElementById('overlay').parentNode.innerHTML = '';
document.body.style['overflow-x'] = 'auto';
document.body.style['overflow-y'] = 'auto';

There are many ways of issuing your own javascript on pages opened in your browser, whatever that might be.

For me on a mac with safari, wrapping the above into a little applescript is easiest. I save this in a file called Ignore-nytimes-paywall.scpt:


tell application "Safari"
	try
		set doc to front document
		do JavaScript "document.getElementById('overlay').parentNode.innerHTML = '';" in doc
		do JavaScript "document.body.style['overflow-x'] = 'auto';" in doc
		do JavaScript "document.body.style['overflow-y'] = 'auto';" in doc
	on error errText number errNum
	end try
end tell

It seems that coming up with your own hack for knocking down the nytimes paywall is the trend these days. We’re all blowing our technological Joshua trumpets ;-).

Update: I’m now more convinced that nytimes is just using this paywall as an experiment. Ignoring the paywall is even easier than I thought:

Readers need only remove “?gwh=numbers” from the URL. They can also clear their browser caches, or switch browsers as soon as they see the subscription prompt. All three of these simple fixes will let them continue reading.

Source

Update:
Seems the paywall organization has changed a little bit and now the client side javascript should be:


document.getElementById('regiwallBackground').style.display = 'none';
document.getElementById('regiwallOverlay').style.display = 'none';
document.body.parentElement.style.overflow = 'scroll';

Including cmath and math.h and using isfinite(x)

Wednesday, April 20th, 2011

I’ve been trying to compile a C++ program with a set of header files one a Solaris SPARC machine. It’s my first experience with GCC outside of the usual intel/unix/mac world and it’s been a bumpy ride.

One problem that I had was that gcc on this machine doesn’t seem to be using the same standards. This was easy to fix once I’d identified it as a problem: just add -ansi to the compiler flags.

The code I’m compiling uses the std::isfinite function. On Macs gets included with cmath, but on the solaris machine it does not. Instead isfinite (notice that this time there is no std namespace) can be included from math.h. So fine, I change the headers to include from math.h instead of cmath and use isfinite instead of std::isfinite.

But! I’m still getting the same old:


...: error: ‘isfinite’ was not declared in this scope

I looked and looked and finally found that earlier in the headers, before getting around to including math.h they include cmath. Including cmath then math.h apparently nukes any ability of retaining isfinite as a global function.

Getting rid of other headers, here’s a simple program that won’t compile:


#include <cstdio>
#include <cmath>
#include <math.h>

int main(int argc,char * argv[])
{
  double b = 1.0;
  bool foo = isfinite(b);
  printf("isfinite(%g): %s\n",b,(foo ? "true" : "false"));

  b = 1.0/0.0;
  foo = isfinite(b);
  printf("isfinite(%g): %s\n",b,(foo ? "true" : "false"));

  return 0;
}

I compile with:


g++ test.cpp -o test -ansi

Okay, at this point I could try to get rid of the cmath include(s), but now I’m starting to mess with these headers a lot and I hadn’t planned on having to edit them at all.

Instead I came up with this solution. Before isfinite is used, I insert:



#define isfinite(x) !std::isinf(x)

Here’s a test program that shows how it works:



#include <cstdio>
#include <cmath>
#include <math.h>
#define isfinite(x) !std::isinf(x)


int main(int argc,char * argv[])
{
  double b = 1.0;
  bool foo = isfinite(b);
  bool bar = isinf(b);
  printf("isfinite(%g): %s\n",b,(foo ? "true" : "false"));
  printf("isinf(%g): %s\n",b,(bar ? "true" : "false"));

  b = 1.0/0.0;
  foo = isfinite(b);
  bar = isinf(b);
  printf("isfinite(%g): %s\n",b,(foo ? "true" : "false"));
  printf("isinf(%g): %s\n",b,(bar ? "true" : "false"));

  return 0;
}

Now, of course, math.h is no longer necessary since we’re not using its isfinite anyway. But the point is to show that it works with both cmath and math.h in the includes.
Update: This doesn’t work… I’m hopefully going to get back to this with something that does.

Determine boundary faces from tetrahedral mesh

Wednesday, April 20th, 2011

Here’s a matlab function that takes a list of tetrahedron indices (4 indices to a row) and finds the triangles that are on the surface of the volume. It does this simply by finding all of the faces that only occur once.


function F = boundary_faces(T)
  % BOUNDARY_FACES
  % F = boundary_faces(T)
  % Determine boundary faces of tetrahedra stored in T
  %
  % Input:
  %  T  tetrahedron index list, m by 4, where m is the number of tetrahedra
  %
  % Output:
  %  F  list of boundary faces, n by 3, where n is the number of boundary faces
  %

  % get all faces
  allF = [ ...
    T(:,1) T(:,2) T(:,3); ...
    T(:,1) T(:,3) T(:,4); ...
    T(:,1) T(:,4) T(:,2); ...
    T(:,2) T(:,4) T(:,3)];
  % sort rows so that faces are reorder in ascending order of indices
  sortedF = sort(allF,2);
  % determine uniqueness of faces
  [u,m,n] = unique(sortedF,'rows');
  % determine counts for each unique face
  counts = accumarray(n(:), 1);
  % extract faces that only occurred once
  sorted_exteriorF = u(counts == 1,:);
  % find in original faces so that ordering of indices is correct
  F = allF(ismember(sortedF,sorted_exteriorF,'rows'),:);
end

With this you can easily determine the vertices of a tetmesh that are on the boundary:


% V are your vertex positions, T are your tet indices
% get boundary faces
F = boundary_faces(T);
% get boundary vertices
b = unique(F(:));
subplot(1,2,1);
% plot boundary positions
plot3(V(b,1),V(b,2),V(b,3),'.');
subplot(1,2,2);
% plot just  boundary faces
trisurf(F,V(:,1),V(:,2),V(:,3),'FaceAlpha',0.3)

Mac OS X Snow Leopard VPN stops working

Monday, April 18th, 2011

All of a sudden my VPN client (the one built into Mac OS X 10.6) asked me for my password. I’d already been logged into the NYU VPN for a few hours. I accidentally clicked cancel.
I tried to reconnect, but now I kept getting this error:


A configuration error occurred. Verify your settings and try reconnecting.

The little icon in the corner would spin and read “Connecting…” but this error would pop up even before it prompted me for my username and password.

So in true Mac style I spent 20 minutes trying to figure out how I could fix this without restarting. (I’m sure restarting would have worked just fine).

Turns out VPN couldn’t connect because another similar process was (already) running. By opening up Terminal.app I issued:


ps -ef | grep racoon

and saw:


    0 84139     1   0   0:00.06 ??         0:00.13 /usr/sbin/racoon

Then I issued:


sudo kill 84139

I reconnected VPN and all is well.

photograph carmen sternwood today

Sunday, April 17th, 2011

photograph carmen sternwood today

http://alecjacobson.com/art/digital/
http://alecjacobson.com/art/

Humans vs computers

Sunday, April 10th, 2011

humans vs computers