Skip to content

Instantly share code, notes, and snippets.

Avatar

Noah Petherbridge kirsle

View GitHub Profile
View Python in vs get.py
import benchmark
class DictBenchmark(benchmark.Benchmark):
each = 5000
def setUp(self):
self.data = dict()
for i in range(0, 10000):
self.data["key_{}".format(i)] = "value {}".format(i)
@kirsle
kirsle / iterative regexp.py
Created Nov 30, 2014
Experiments for upgrading RiveScript's tag processing algorithm, to support nested tags such as <set oldname=<get name>> which previously didn't work, as I was doing a simple find/replace one tag-type at a time and <set> always came before <get>.
View iterative regexp.py
#!/usr/bin/env python
"""Experiments to upgrade RiveScript's tag processing algorithm."""
from collections import deque
import re
import random
tests = [
"<set oldname=<get name>>I thought your name was <get oldname>?",
@kirsle
kirsle / redis-json-lock-test.py
Created Dec 11, 2014
A test for Redis-based file locking when rapidly updating a JSON document (doesn't work)
View redis-json-lock-test.py
#!/usr/bin/env python
"""Script to stress test rapid JSON DB writes.
1. When reading from disk, flock(LOCK_SH) is used on the file handle.
2. When writing to disk:
a. A lock is acquired in a Redis instance as added protection
b. File is locked with LOCK_EX during the write
c. After the file is written (while still Redis-locked), it attempts to read
the file again immediately (LOCK_SH) to verify that it wrote successfully
@kirsle
kirsle / simple-cracker.pl
Created Dec 19, 2014
Just a dead simple "password cracker" that will brute force your plain lowercased passwords (letters only, no numbers or capitals).
View simple-cracker.pl
#!/usr/bin/perl
# Simple password cracker. Tries every combination of plain lowercased
# passwords, from "a", "b", ..., "z", "aa", "ab", ... "az", "ba", "bb" ...
use 5.18.0;
use Time::HiRes qw(time);
use Digest::MD5 qw(md5_hex);
my $victim = $ARGV[0];
@kirsle
kirsle / tcp-server.diff
Created Feb 22, 2015
RiveScript Node TCP Server with Logging
View tcp-server.diff
diff --git a/node/tcp-server.js b/node/tcp-server.js
index 22b383f..08e9c02 100644
--- a/node/tcp-server.js
+++ b/node/tcp-server.js
@@ -4,6 +4,7 @@
//
// Run this and then telnet to localhost:2001 and chat with the bot!
+var fs = require("fs");
var net = require("net");
View multiple-inheritance.py
#!/usr/bin/env python
class WorkerBase(object):
def __init__(self, *args, **kwargs):
print "WorkerBase init"
pass
class DBWorker(WorkerBase):
def __init__(self, *args, **kwargs):
print "DBWorker init"
View Binary download.coffee
##
# Problem: sending a binary download in ExpressJS.
#
# I was trying to proxy download a binary file from S3 and serve it to the user with a different name.
# Using the `request` module didn't work; text files came back fine but binary files would be corrupted
# in strange ways (see attached diff).
#
# I ended up using the built-in `https` module and doing it the hard way.
#
# My theory: the request module expects to only work with text and was performing some UTF-8 coercion
View xclick.pl
#!/usr/bin/perl
# requires: libX11-devel, libXt-devel, libXtst-devel, /usr/bin/xinput
# sudo cpanm X11::GUITest
use threads;
use IO::Pty::Easy;
use IO::Handle;
use X11::GUITest qw(ClickMouseButton :CONST);
View twilio-rivescript.py
# minimal example of linking RiveScript to Twilio (untested)
from flask import Flask, request, redirect
from rivescript import RiveScript
import twilio.twiml
app = Flask(__name__)
bot = RiveScript()
bot.load_directory("brain")
bot.sort_replies()
View keybase.md

Keybase proof

I hereby claim:

  • I am kirsle on github.
  • I am kirsle (https://keybase.io/kirsle) on keybase.
  • I have a public key whose fingerprint is 03AC B9F9 5CE5 A920 871E 94C5 9255 42ED E2E7 1CDA

To claim this, I am signing this object: