Skip to content

Instantly share code, notes, and snippets.

@danmactough
danmactough / ip-addresses
Last active January 3, 2016 22:39
ThrustVPS hacked VPS postmortem. These are the unique, failed login attempts *AFTER* the hacker reinstalled the OS. Also, the running processes (note dropbear).
Count Address
----- -------
12856 117.239.9.229
390 117.21.127.215
301 216.126.110.116
169 1.93.37.231
136 119.90.37.14
80 115.68.22.162
56 bb220-255-26-152
50 60-199-196-144.s
@danmactough
danmactough / comment.md
Created December 31, 2013 00:22
Isaac's description of process.nextTick vs. setImmediate

I agree the point you’re making here, 100%. However, a slight correction about Node’s APIs.

First of all, process.nextTick is actually first in, first out. Proof:

$ node -e 'process.nextTick(console.log.bind(console, 1)); process.nextTick(console.log.bind(console, 2))'
1
2
@danmactough
danmactough / localport.sh
Created December 17, 2013 15:21
Block port except via localhost. Optionally, pass `-D` as second argument to remove the block.
#/bin/bash
PORT=$1
ACTION=${2:-"-A"}
iptables $ACTION INPUT -p tcp -s localhost --dport $PORT -j ACCEPT
iptables $ACTION INPUT -p tcp --dport $PORT -j DROP
@danmactough
danmactough / tunnel
Created December 13, 2013 22:45
Make it easy to create an ssh tunnel
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: `basename $0` remote remote-port local-port"
exit 1
fi
ssh -N -L $3:localhost:$2 $1
@danmactough
danmactough / rtunnel
Created December 13, 2013 22:44
Make it easy to create a reverse ssh tunnel
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: `basename $0` remote remote-port local-port"
exit 1
fi
ssh -N -R $2:localhost:$3 $1
@danmactough
danmactough / no-with.js
Created December 13, 2013 05:42
Closure instead of with
[dan@Dans-MacBook-Pro code]$ node
> var code = 'function printer (val) { return val; }; var result = printer(a); console.log(result);'
undefined
> eval(code)
ReferenceError: a is not defined
at eval (eval at <anonymous> (repl:1:7), <anonymous>:1:62)
at repl:1:2
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
@danmactough
danmactough / if-piper.js
Created December 2, 2013 17:21
Pseudo-code for conditional piping
var feed = 'http://somefeed.com/rss'
var req = request(feed)
req.on('response', function (response) {
if (sometest(feed)) {
req.pipe(iconv).pipe(parser)
}
else {
req.pipe(parser)
}
})
@danmactough
danmactough / Cargo.toml
Created December 28, 2015 01:16
Dining Philosophers
[package]
name = "dining_philosophers"
version = "0.1.0"
authors = ["Dan MacTough <danmactough@gmail.com>"]
[dependencies]
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"not": {
"bool": {
"must": {
@danmactough
danmactough / wrapper.js
Created October 2, 2013 14:07
URL fetching wrapper for feedparser v.16
var FeedParser = require('feedparser')
, request = require('request')
, STATUS_CODES = require('http').STATUS_CODES;
module.exports = function (feed, cb) {
var parser = new FeedParser();
var req = request(feed);
var items = [];
var _called = false;