Skip to content

Instantly share code, notes, and snippets.

@mcroydon
mcroydon / nntpd.js
Created February 2, 2011 05:45
A minimal NNTP implementation in node.js
var net = require('net');
var END = '\r\n';
var groups = ['nodejs.test'];
var articles = {
'<1@127.0.0.1>' : {body : 'An article.'},
'<2@127.0.0.1>' : {body : 'Another article.'},
};
# Download all current FAA sectional GeoTIFFs (zipped)
import urllib, os, csv
from lxml.html.soupparser import fromstring
FAA_CHART_URL = 'http://aeronav.faa.gov/index.asp?xml=aeronav/applications/VFR/chartlist_sect'
BASE_CONTENT_URL = 'http://aeronav.faa.gov/'
DOWNLOAD_DIR = 'download'
data = urllib.urlopen(FAA_CHART_URL).read()
#User preferences for Reader Booklet
#Thu Sep 16 01:05:28 GMT 2010
FONT_SIZE=17
LINE_SPACING=3
DICTIONARY=The New Oxford American Dictionary
JUSTIFICATION=full
HORIZONTAL_MARGIN=40
LAST_BOOK_READ=/mnt/us/documents/Kindle_Users_Guide.azw
FONT_FAMILY=serif
diff --git a/example/server.js b/example/server.js
index 167fc43..db758a2 100644
--- a/example/server.js
+++ b/example/server.js
@@ -61,4 +61,16 @@ io.on('connection', function(client){
client.on('disconnect', function(){
client.broadcast({ announcement: client.sessionId + ' disconnected' });
});
-});
\ No newline at end of file

finger_server.js

An extremely minimal implementation of the Finger protocol using node.js.

To run (Finger uses port 79 which requires sudo):

sudo node finger_server.js
<!DOCTYPE html>
<html>
<head>
<title>My Whisper Blog</title>
</head>
<body>
<section>
<header><a href='/'>My Whisper Blog</a></header>
{{error}}
// gopher.js - a minimal gopher implementation using node.js
// Released under the 3 clause BSD license by Matt Croydon <mcroydon@gmail.com> (http://postneo.com)
var net = require('net');
net.createServer(function (socket) {
socket.setEncoding("ascii");
socket.on("data", function (data) {
if (data === '\r\n') {
console.log('Serving index.');
votes CF
"back in black" => { 201005211200 => '1', 201005201159 => '1', 201005201157 => '1', 201005011900 => '1', 201004190600 => '1' },
"black album" => { 201005021800 => '1', 201005010600 => '1' },
"black star" => { 201005011000 => '1' }
cached_counts CF
"back in black" => { 'cached_count' => 2, 'counted_until' => 201005011931 },
"black album" => { 'cached_count' => 1, 'counted_until' => 201005010600 }
# chl, 2010-04-27
# http://blog.tech.stylefeeder.com/2008/05/27/generating-primary-keys/
import math
NUM = "0123456789"
LOWER = "abcdefghijklmnopqrstuvwxyz"
UPPER = LOWER.upper()
ALPHANUM = NUM + LOWER + UPPER
ASCII_94 = [chr(33 + x) for x in xrange(94)]