Skip to content

Instantly share code, notes, and snippets.

View scripting's full-sized avatar

Dave Winer scripting

View GitHub Profile
@scripting
scripting / fsDeleteDirectory.js
Created March 25, 2016 13:53
Recursively delete a directory and all its subs and files it contains.
function fsDeleteDirectory (folderpath, callback) { //3/25/16 by DW
if (folderpath [folderpath.length - 1] != "/") {
folderpath += "/";
}
fs.readdir (folderpath, function (err, list) {
if (err) {
console.log ("fsDeleteDirectory: err.message == " + err.message);
}
else {
function doListItem (ix) {

I need a way to write WebSocket client code that runs on a server in Node.js.

What it must do: Exactly what this browser-based app does, only running on a server, without the UI stuff.

https://github.com/scripting/1999client/blob/master/code.js#L133

It would make so much sense if Node implemented exactly the browser API for WebSockets, native. So much of Node works that way. But this is one of those times when it doesn't.

There are a few toolkits that do WebSockets on the server. But there isn't simple clean sample code that I've been able to convert to this application. I tried! :-)

@scripting
scripting / config.json
Last active November 1, 2016 15:55
An example config.json file that specifies a set of panels on your River5 installation's home page.
{
"maxRiverItems": 300,
"flAddItemsFromNewSubs": false,
"homePage": {
"panels": [
{
"title": "Dave",
"river": "iowa.js"
},
{
function nukeDisabledMenuItems () {
$(".dropdown-menu li").each (function () {
if ($(this).hasClass ("disabled")) {
$(this).children ().first ().attr ("onclick", ""); //nuke the command
}
});
}
var ws = require ("nodejs-websocket");
var myPort = 1337;
function handleConnection (conn) {
conn.on ("text", function (s) {
var returnstring = s.toUpperCase () + "!!!";
console.log ("handleConnection: returning " + returnstring);
conn.sendText (returnstring)
});
}
<html>
<head>
<title>WebSocket client example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://fargo.io/code/jquery-1.9.1.min.js"></script>
<link href="http://fargo.io/code/ubuntuFont.css" rel="stylesheet" type="text/css">
<script>
var urlMySocket = "ws://localhost:1337/";
var ctSeconds = 0;
function useStylesheet (url) {
var head = document.getElementsByTagName ("head") [0];
var styleSheet = document.createElement ("link");
styleSheet.rel = "stylesheet";
styleSheet.type = "text/css";
styleSheet.href = url;
head.appendChild (styleSheet);
}
function includeScriptCode (url, callback) {
var head = document.getElementsByTagName ("head") [0];
var x = document.createElement ("script");
x.src = url;
if (callback !== undefined) {
x.onload = callback;
}
head.appendChild (x);
}
@scripting
scripting / aboutdialog.html
Last active September 14, 2015 02:12
Example source for the About dialog for a river of news page.
<html>
<head>
<title>aboutdialog test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://fargo.io/code/jquery-1.9.1.min.js"></script>
<link href="http://fargo.io/code/bootstrap.css" rel="stylesheet">
<script src="http://fargo.io/code/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://fargo.io/code/fontAwesome/css/font-awesome.min.css"/>
@scripting
scripting / mlbriver.html
Last active September 30, 2016 02:06
Source code for mlbriver.com v2
<html>
<head>
<title>mlbriver.com</title>
<!--
This is a lightly modified version of the source for mlbriver.com.
I took out the hit counting code, because that's specific to the way I run my sites.