Skip to content

Instantly share code, notes, and snippets.

View scoates's full-sized avatar

Sean Coates scoates

View GitHub Profile
var readline = require('readline');
module.exports = readline;
readline.Interface.prototype.cursorToEnd = function() {
// place the cursor at the end of the current line
this.output.write(
'\x1b[0G\x1b[' + (
this._promptLength + this.line.length
) + 'C'
sarcasm:~/src/tmp$ cat repl.js
repl = require("repl");
repl.start("testrepl> ");
sarcasm:~/src/tmp$ node repl.js
testrepl> 5+5
10
testrepl> sarcasm:~/src/tmp$ echo "5+5" | node repl.js
node.js:63
throw e;
browser
.chain
.session()
.and(function (browser) {
browser
.chain
.open('/')
.assertElementPresent('link=Log out')
.clickAndWait('link=Log out')
.assertElementPresent('link=Log in')
browser
.chain
.session()
.and(function (browser) { // log out
try {
browser
.open('/')
.assertElementPresent('link=Log out')
.clickAndWait('link=Log out')
.assertElementPresent('link=Log in')
var Step = require('./lib/step');
Step(
function () { console.log("one"); },
function () { console.log("two"); }
);
@scoates
scoates / Stack.php
Created December 12, 2010 21:24 — forked from stenehall/New stack
<?php
/*
* README
* mkdir one && mkdir two && mkdir three && touch one/blueprint-1.3.css && touch one/foobar.css && touch two/jquery.js && touch three/jquery-1.4.js
*
*/
include('stack.php');
<?php
/**
* Sends statistics to the stats daemon over UDP
*
**/
class StatsD {
/**
@scoates
scoates / gist:1711131
Created January 31, 2012 15:40 — forked from chartjes/gist:1711104
Hands On Node File System Exercise #3
var fs = require('fs');
function readBytes(filename, position) {
fs.open(filename, 'r', function(err, fd) {
if (err) {
console.log(err.message);
return;
}
var readBuffer = new Buffer(5);
@scoates
scoates / gist:3355357
Created August 15, 2012 03:11
MongoDB: findandmodify seems to use the wrong query on the update command
> db.runCommand({ findAndModify: 'assets', query: {$or: [ { "_id" : "4ff70c97c87a97bc7f000002" }, { "_id" : ObjectId("4ff70c97c87a97bc7f000002") } ]}, update: {$set: {private: true}}, new: true, upsert: false })
{
"lastErrorObject" : {
"updatedExisting" : true,
"n" : 1,
"connectionId" : 1317,
"err" : null,
"ok" : 1
},
"value" : {
@scoates
scoates / timeline
Last active December 10, 2015 09:29
Times each line of stdin
#!/usr/bin/env python
import time
from sys import stdin, stdout, argv, exit
try:
if argv[1] == 'help' or argv[1] == '--help' or argv[1] == '-h':
print "%s: times each line of stdin.\n Optional parameter is a float of a threshold. (defaults to 2.0)" % argv[0]
exit(255);
else: