Skip to content

Instantly share code, notes, and snippets.

View dresende's full-sized avatar
🇺🇦
Free Ukraine

Diogo Resende dresende

🇺🇦
Free Ukraine
View GitHub Profile

Readline

To use this module, do require('readline').

rl.createInterface(input, output, completer)

Takes two streams and creates a readline interface. The completer function is used for autocompletion. When given a substring, it returns [substr, completedStr]. TODO: write some code to make sure I'm right.

createInterface is commonly used with process.stdin and process.stdout in order to accept user input:

@dresende
dresende / ldapjs-addrbook.js
Created August 26, 2011 18:06
LDAP Addressbook using ldapjs
// MySQL test: (create on database 'abook' with username 'abook' and password 'abook')
//
// CREATE TABLE IF NOT EXISTS `users` (
// `id` int(5) unsigned NOT NULL AUTO_INCREMENT,
// `username` varchar(50) NOT NULL,
// `password` varchar(50) NOT NULL,
// PRIMARY KEY (`id`),
// KEY `username` (`username`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
// INSERT INTO `users` (`username`, `password`) VALUES
@dresende
dresende / output.txt
Created October 2, 2012 15:12
Using momentjs and node-time, having an UTC date, format it in any timezone
# this was runned on the first dates below (Oct 2 2012, 3:10 PM UTC)
UTC: Tuesday, October 2 2012 3:10 PM
LX: Tuesday, October 2 2012 4:10 PM
NY: Tuesday, October 2 2012 11:10 AM
TKY: Wednesday, October 3 2012 12:10 AM
3 months later...
UTC: Wednesday, January 2 2013 3:10 PM
LX: Wednesday, January 2 2013 3:10 PM
<?xml version="1.0" encoding="utf-8"?>
<Root>
<type>OF</type>
<output>archive</output>
<uid>13557592400997</uid>
<OF>
<Number>86799</Number>
<Date>2012-11-28 16:46:15</Date>
<DeliveryDate>2013-08-20</DeliveryDate>
<WeekNumber>34</WeekNumber>
@dresende
dresende / fetch_pull_request.sh
Created June 5, 2013 09:28
Fetch a single github pull request
# fetch pull request N to (new) localbranch
git fetch origin pull/N/head:localbranch
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am dresende on github.
  • I am dresende (https://keybase.io/dresende) on keybase.
  • I have a public key whose fingerprint is CFBD 875A 4D0B 2D43 6A86 72F9 1166 9F08 1BBF 85CA

To claim this, I am signing this object:

@dresende
dresende / index.js
Created September 29, 2015 21:49
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var modbus = require("modbus-tcp");
var client = new modbus.Client();
var server = new modbus.Server();
// link client and server streams together
client.writer().pipe(server.reader());
server.writer().pipe(client.reader());
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
const people = [
{ name: "John", ranking: 3 },
{ name: "Jane", ranking: 8 },
{ name: "Joe", ranking: 2 },
{ name: "Jessica", ranking: 9 },
];
console.log("average", rank_avg(people));
console.log("sorted", rank_sort(people).map((person) => (person.name)));