Ugh! Turns out if you don’t use a new Parser for each request you end up exiting with “Error: Can’t set headers after they are sent.”
Very annoying!
I am kind of a big deal…
Ugh! Turns out if you don’t use a new Parser for each request you end up exiting with “Error: Can’t set headers after they are sent.”
Very annoying!
I was transferring my latest creation over to my hosted Ubuntu server and came across the most annoying error. I had to reinstall the NodePie module because it relies on compiled C code. I kept getting an error though about something called lib-expat.
Anyhow, turns out you need to apt-get a new library:
sudo apt-get install libexpat1-dev
GitHub to the rescue:https://github.com/astro/node-xmpp/issues/33
So I wanted to move a larger number of records from MongoDB to CouchDB. Here are the basic steps I took:
curl -d @output.json -X POST $DB/_bulk_docs -H “Content-Type: application/json”
Suppose you want to have a bunches of DIVs contained inside of a List Item… AND you want them to not mess with the height of the List Item and appear as a line of text?
Well then, take this sample HTML:
<li> <div class="inspection"> <div class="date"><a href="/report/1430/9115/">9-16-2010</a></div> <div class="inspection-type">License Renewal </div> <div class="violations">0 Violations</div> </div> </li>
And apply this CSS:
.inspection {
overflow: hidden;
vertical-align: middle;
display: inline-block;
}
li {
margin-left: 15px;
list-style-type: disc;
list-style-position: inside;
}
I recently just wasted a lot of time trying to get PostGIS up and running on OSX Lion. I wanted to do this so I could pull in Open Street Map data for the DC region and then play with it in QGIS and import it into Tilemill. I will be the first to admit that this is a rather complex toolchain, but it shouldn’t have been as difficult as it was.
On the off chance I can save someone time, I will recap what I did… and some of the misstep.
My big misstep was trying to use the precompiled binaries from KyngChaos. While they work fine, the OSM importer for PostGIS always SegFaulted when I tried running it against these versions. I even tried compiling the importer from source code and couldn’t get it work.
Here is what to do:
JSDOM is a great little module for NodeJS which lets you parse a DOM on the server. The only problem is that it has a memory leak. Not a big deal if you are only going to instantiate a couple times. A little trickier if you are screen scraping and need to call it 1000s of times. I luckily found a work around. Instead of creating a new window every time you want to parse some code, simply keep the same window around and switch what it is displaying:
From the google groups:
I’m basically doing this:
var jsdom = require(‘jsdom’);
var document = jsdom.jsdom(‘<html><body>’);
var window = document.createWindow();
var JQUERY_URL = ‘http://localhost/js/jquery-1.4.4.min.js’;
function foo(text) {
document.innerHTML = ‘<html><body>’ + text;
jsdom.jQueryify(window, JQUERY_URL, function() {
var $ = window.$;
console.log(document.innerHTML);
});
setInterval(function() {
foo(“Text”);
And the process’ memory increases and eventually terminates. How do
you suggest I should reuse the DOM?
I am trying this for now:
function foo(text) {
document.innerHTML = ‘<html><body>’ + text;
if (!window.$) {
jsdom.jQueryify(window, JQUERY_URL, function() {
var $ = window.$;
console.log(document.innerHTML);
});
} else {
var $ = window.$;
console.log(document.innerHTML);
}
}
When you get a jQuery object back from a selector, you general loop through all of the elements it contains using .each(). However I wanted to use a For Loop because I wanted to access a bunch of elements at once. I am scrapping a table and I might want to access multiple elements to pull data from.
Figuring out how to do this was a little tricky. Luckily it is very easy to do:
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<script>
$(“body”).find(“div”).eq(2).addClass(“blue”);
</script>
Simply use .eq(index) to access a particular element in the jQuery object.
XCode 4.1 is now free in the App Store. I wanted to completely remove 3.0 version I had. Luckily there is a simple command line option for doing an uninstall:
sudo /Developer/Library/uninstall-devtools –mode=all
Jade is an HTML templating language that works with Node.js and a bunch of other languages. It takes structured templates and converts them into HTML. Jade uses indentation to show what code should be within an HTML tag.
It is also possible to use variables to generate text, they call it Interpolation and it is a very handy feature. However, it is sometimes a little tricky to figure out how to use variables for attributes in tags.
For example if you want the variable local to serve a link in an Anchor tag, this would work:
a(href=local) Test Link
You can also combine variables and text:
a(href=’http://localhost:3000/page/’ + next_page ) Next
Doing the same for DIV IDs was a little trickier though. Since there is short had for assigning IDs, I thought I could just paste the variable in the shorthand. That didn’t work. However, using an approach similar to the Anchor tag does. Try this for using variables to assign the ID for a DIV:
div(id=permit_id)
It is always fun to head out to lunch and find the latest in Hybrid technology.


