Skip to content

Commit

Permalink
personal toolbox changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrising committed Oct 17, 2015
1 parent 2c6b3b3 commit 280aefc
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 1 deletion.
4 changes: 3 additions & 1 deletion html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<script type="text/javascript" src="js/xkcd.js"></script>
<script type="text/javascript" src="js/mochilite.js"></script>
<script type="text/javascript" src="js/javascript.js"></script>
<script type="text/javascript" src="js/lambdamoo.js"></script>
<script type="text/javascript" src="js/personal.js"></script>
</head>
<body>
<div id="pagealert" title="Press any key for next page of text"> --More-- </div>
Expand All @@ -38,7 +40,7 @@ <h1>Console</h1>
</div>
</div>
<div id="credit">Based on XKCD CLI: <a href="http://github.com/chromakode/xkcdfools">Source code</a>.</div>
<p style="text-align: right">Available frameworks: <a href="#" onclick="Terminal.runCommand('j:'); return false;">Javascript</a>, <a href="#" onclick="Terminal.runCommand('x:'); return false;">XKCD Shell</a>.</p>
<p style="text-align: right">Available frameworks: <a href="#" onclick="Terminal.runCommand('j:'); return false;">Javascript</a>, <a href="#" onclick="Terminal.runCommand('x:'); return false;">XKCD Shell</a>, <a href="#" onclick="Terminal.runCommand('l:'); return false;">LambdaMOO Pirates</a>.</p>
</body>
</html>

29 changes: 29 additions & 0 deletions html/js/lambdamoo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var LambdaMOOProcess = {
conn: null,

init: function(terminal) {
this.conn = new WebSocket("ws://existencia.org:8080/");
this.conn.onopen = function(e) {
terminal.print("Connection established!");
window.setTimeout(function() {
LambdaMOOProcess.conn.send("CO guest nopass");
window.setInterval(function() {
LambdaMOOProcess.conn.send("_/_");
}, 1000);
}, 500);
};
this.conn.onmessage = function(e) {
terminal.print(e.data);
};
},

config: {
prompt: '>> ',
},

handle: function(terminal, content) {
this.conn.send(content);
}
};

Terminal.processCatalog['l'] = LambdaMOOProcess;
66 changes: 66 additions & 0 deletions html/js/personal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ShellProcess.commands['arch'] = function(terminal) {
var sources = ['laptop', 'backups', 'pics', 'cards', 'projects', 'existencia', 'blogs', 'contacts', 'email', 'folders'];
var index = Math.floor(Math.random() * sources.length);
terminal.print("Revisit something in " + sources[index] + '.');
};

ShellProcess.commands['ts'] = function(terminal) {
var args = Array.prototype.slice.call(arguments);

urlargs = {
pass: terminal.supass,
op: args[1]
};
for (var ii = 2; ii < args.length; ii++) {
if (args[ii].match(/\d/) && args[ii].match(/^\d*\.?\d*$/)) {
urlargs['dur'] = args[ii];
terminal.print("Duration: " + args[ii]);
}
else if (args[ii].match(/^\d\d:\d\d$/)) {
urlargs['start'] = args[ii];
terminal.print("Start: " + args[ii]);
}
else
urlargs['task'] = args[ii];
}

$.post("time.php", urlargs, function(result) {
terminal.print(result);
});
};

ShellProcess.commands['post'] = function(terminal) {
var args = Array.prototype.slice.call(arguments);
args.shift(); // terminal
category = args.shift();
if (args.length > 0)
doPost(terminal, category, args.join(' '));
else {
gettext(terminal, 'post> ', function(allcontent) {
doPost(terminal, category, allcontent);
});
}
};

function doPost(terminal, category, content) {
terminal.setWorking(true);
$.post("post.php", {
category: category,
content: content,
pass: terminal.supass
}, function(result) {
terminal.print(result);
terminal.setWorking(false);
});
}

// Entertain me!
ShellProcess.commands['ent'] = function(terminal) {
terminal.setWorking(true);
$.get("entertain.php", {
pass: terminal.supass
}, function(result) {
terminal.print(result);
terminal.setWorking(false);
});
};
45 changes: 45 additions & 0 deletions html/js/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,25 @@ ShellProcess.commands['su'] = function(terminal, path) {
}
};

function gettext(terminal, prompt, callback) {
var oldprompt = terminal.setPrompt(prompt);
var allcontent = '';

terminal.inputConsumer = function(terminal, content) {
if (content == null) {
callback(allcontent);
terminal.inputConsumer = null;
terminal.setPrompt(oldprompt);
} else {
this.print($('<p>').addClass('command').text(this.config.prompt + content));
if (allcontent)
allcontent += "\n";
allcontent += content;
}
};
}


ShellProcess.commands['reddit'] = function(terminal, num) {
num = Number(num);
if (num) {
Expand Down Expand Up @@ -445,6 +464,32 @@ ShellProcess.commands['wget'] = ShellProcess.commands['curl'] = function(termina
}
};

ShellProcess.commands['telnet'] = function(terminal) {
var args = Array.prototype.slice.call(arguments);
args.shift(); // terminal
var ipp = args.shift(); // like existencia.org:9999

var conn = new WebSocket("ws://" + ipp + "/");
conn.onopen = function(e) {
terminal.print("Connection established!");
};
conn.onmessage = function(e) {
terminal.print(e.data);
};

var oldprompt = terminal.setPrompt('telnet> ');

terminal.inputConsumer = function(terminal, content) {
if (content == null) {
terminal.inputConsumer = null;
terminal.setPrompt(oldprompt);
} else {
this.print($('<p>').addClass('command').text(this.config.prompt + content));
conn.send(content);
}
};
};

ShellProcess.commands['write'] =
ShellProcess.commands['irc'] = function(terminal, nick) {
if (nick) {
Expand Down
24 changes: 24 additions & 0 deletions html/ss/entertain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
require_once('/home/jrising/common/base.php');
require_once(comdir("sql/dbfuncs.php"));

if ($_POST['pass'] != 'qhww0c') {
echo "Password failure.";
exit(0);
}

// Try sinfest
$rss = simplexml_load_file("http://existencia.org/feeds/comics/sinfest.pl");

for ($rss->channel->item as $item) {
$row = dbgetrow("select id from glanced where source = 'sinfest' and link = %s", $item->link);
if (!$row) {
dbquery("insert into glanced (source, link) values ('sinfest', %s)", $link);
echo $item->description;
exit();
}
}

echo "Entertain yourself!";

?>
34 changes: 34 additions & 0 deletions html/ss/ical.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once('/home/jrising/common/base.php');
require_once(comdir("sql/dbfuncs.php"));

$dbc = dbconnect("memoir", "ignore");

$rows = dbgetarray("select id, task, UNIX_TIMESTAMP(time_start), duration_hours - adjusted_hours, UNIX_TIMESTAMP(last_updated) from times");

$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
";

foreach ($rows as $row) {
if (!$row[3])
continue;
$ical .=
"BEGIN:VEVENT
UID:memoir-times-" . md5($row[0]) . "@existencia.org
DTSTAMP:" . gmdate('Ymd', $row[4]).'T'. gmdate('His', $row[4]) . "Z
DTSTART:" . gmdate('Ymd', $row[2]).'T'. gmdate('His', $row[2]) . "Z
DTEND:" . gmdate('Ymd', $row[2] + $row[3]*3600).'T'. gmdate('His', $row[2] + $row[3]*3600) . "Z
SUMMARY:" . $row[1] . "
END:VEVENT
";
}

$ical .= "
END:VCALENDAR";

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=calendar.ics');
echo $ical;
14 changes: 14 additions & 0 deletions html/ss/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require_once('/home/jrising/common/base.php');
require_once(comdir("sql/dbfuncs.php"));

if ($_POST['pass'] != 'qhww0c') {
echo "Password failure.";
exit(0);
}

$dbc = dbconnect("memoir", "ignore");
dbquery("insert into entries (content, category) values (%s, %s)", $_POST['content'], $_POST['category']);
echo "Posted.";

?>
23 changes: 23 additions & 0 deletions html/ss/status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require_once('/home/jrising/common/base.php');
require_once(comdir("sql/dbfuncs.php"));

$args = array_merge($_POST, $_GET);

if ($args['pass'] != 'qhww0c') {
echo "Password failure.";
exit(0);
}

$dbc = dbconnect("memoir", "ignore");

if ($args['op'] == 'register') {
$process_id = dbquery("insert into processes (server, name) values (%s, %s)", $args['server'], $args['name']);
echo $process_id;
} else if ($args['op'] == 'update') {
dbquery("update processes set message = %s, type = %s where id == %d", $args['message'], $args['type'], $args['id']);
if ($args['type'] == 'done')
dbquery("delete from processes where process_id = %d", $args['id']);
} else if ($args['op'] == 'notify') {
dbquery("insert into process_logs (process_id, message, type) values (%d, %s, %s)", $args['id'], $args['message'], $args['type']);
}
77 changes: 77 additions & 0 deletions html/ss/time.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
require_once('/home/jrising/common/base.php');
require_once(comdir("sql/dbfuncs.php"));

$args = array_merge($_POST, $_GET);

if ($args['pass'] != 'qhww0c') {
echo "Password failure.";
exit(0);
}

$dbc = dbconnect("memoir", "ignore");

if ($args['start']) {
if (!strpos($args['start'], ' '))
$args['start'] = date('Y-m-d ') . $args['start'];
}

if ($args['op'] == 'a') {
// Check what's active
$row = dbgetrow("select task, time_start, adjusted_hours from times where time_start is not null and duration_hours is null");
if ($row) {
if ($row[2] > 0)
echo "Active: " . $row[0] . ": " . $row[1] . " (-" . $row[2] . ") -";
else
echo "Active: " . $row[0] . ": " . $row[1] . " -";
} else {
echo "None active.";
}
} else if ($args['op'] == 'd') {
// How much time have we spent on what in the last 24 hours?
$row = dbgetarray("select task, time_start, duration_hours - adjusted_hours from times where time_start is not null and to_days(time_start) == to_days(now)");
print_r($row);
} else if ($args['op'] == '/') {
// start, stop, or swap
if ($args['start'])
dbquery("update times set duration_hours = timestampdiff(minute, time_start, %s) / 60 where time_start is not null and duration_hours is null", $args['start']);
else
dbquery("update times set duration_hours = timestampdiff(minute, time_start, now()) / 60 where time_start is not null and duration_hours is null");
$had_active = mysql_affected_rows();
if ($args['task']) {
if ($args['start'])
dbquery("insert into times (task, time_start) values (%s, %s)", $args['task'], $args['start']);
else
dbquery("insert into times (task, time_start) values (%s, now())", $args['task']);

if ($had_active > 0)
echo "Task swapped.";
else
echo "Task started.";
} else
echo "Task ended.";
} else if ($args['op'] == '-') {
// always duration; may have task and start
dbquery("update times set adjusted_hours = adjusted_hours + %f where time_start is not null and duration_hours is null", $args['dur']);
$had_active = mysql_affected_rows();
if ($args['task']) {
if ($args['start']) {
dbquery("insert into times (task, time_start, duration_hours) values (%s, %s, %f)", $args['task'], $args['start'], $args['dur']);
if ($had_active)
echo "Added timed task within active task.";
else
echo "Added timed task.";
} else {
dbquery("insert into times (task, duration_hours) values (%s, %f)", $args['task'], $args['dur']);
if ($had_active)
echo "Added interval within active task.";
else
echo "Added interval.";
}
} else {
if ($had_active)
echo "Added break.";
else
echo "Nothing to break from.";
}
}

0 comments on commit 280aefc

Please sign in to comment.