Skip to content

Instantly share code, notes, and snippets.

Max Goodhart chromakode

Block or report user

Report or block chromakode

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chromakode
chromakode / gist:e6baee16d87cad494921
Created Jul 8, 2014
salt-ssh pillar data workaround
View gist:e6baee16d87cad494921
# salt-ssh doesn't support sending pillar data, so we have to embed it in the state files...
/etc/openvpn/server.key:
file.managed:
- contents: |
{{ pillar['openvpn']['server_key'] | indent(8) }}
- user: root
- group: root
- mode: 600
View gist:4cbcc6da0418c0235b4a
var importExpr = /^(\s*)(import\s+[^=+*"'\r\n;\/]+|from\s+[^=+"'\r\n;\/]+)(;|\/|$)/gm;
function replaceImport(raw, p1, p2, p3) {
if (!/\/\//.test(p1)) {
return p1 + 'jsio(\'' + p2 + '\')' + p3;
}
return raw;
}
var requireExpr = /^(.*)require\(['"]([^=+*"'\r\n;]+)['"]\)(;|\/|$)/gm;
@chromakode
chromakode / gist:42198
Created Jan 1, 2009
Storing IP addresses in a tree using a lightweight defaultdict implementation.
View gist:42198
function defaultdict(default) {
this._default = default;
};
defaultdict.prototype = {
get: function(key) {
if (!key in this) { this[key] = this._default(key); }
return this[key];
}
}
@chromakode
chromakode / IRCTriviaHelper.py
Created Jan 16, 2009
There's a running complaint in #reddittrivia that people are using Google to cheat, so here's a simple proof of concept using the Yahoo search API to even the playing field a little.
View IRCTriviaHelper.py
import re
import string
import readline
import textwrap
from yahoo.search.web import WebSearch
APP_ID = "IRCTriviaHelper"
def bullet(lines):
return ["\n".join(textwrap.wrap(line, 77, initial_indent=" - ", subsequent_indent=" ")) for line in lines]
@chromakode
chromakode / skirmish.py
Created May 8, 2009
IMCS wrapper script -- incomplete
View skirmish.py
import sys
import os.path
import socket
import subprocess
from urlparse import urlparse, ParseResult
from optparse import OptionParser
BUF_SIZE = 1024
DEFAULT_IMCS_PORT = 3589
VERBOSE = False
@chromakode
chromakode / karmabot.py
Created Nov 8, 2009
IRC bot to keep track of descriptions of words and their karma.
View karmabot.py
import sys
import random
import re
import time
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol, ssl
from twisted.python import log
try:
View drizzle_db.py
from drizzle import libdrizzle as _libdrizzle
libdrizzle = _libdrizzle.Drizzle()
def connect(*args, **kwargs):
connection = Connection(*args, **kwargs)
connection._connect()
return connection
class Connection:
@chromakode
chromakode / header_nanny.py
Created Feb 20, 2010
A somewhat scary header munger. You'd better have good version control!
View header_nanny.py
#!/usr/bin/env python
from __future__ import print_function
import sys
import os, os.path
import shutil
import optparse
import re
comment_ignore_re = re.compile(r"#!.+")
View gist:320330
def _iter_driver_output(self):
while self.driver_stack:
curdriver = self.driver
# Iterate over the current driver until it changes.
for output in curdriver.get_input():
yield output
# If the driver has changed, stop iterating over the old one.
if self.driver is not curdriver:
break
View gist:327671
# <snip>
for line in f:
m = LOG_RE.match(line)
if m:
when = time.mktime(time.strptime(m.group("when"), "%d-%m-%Y %H:%M:%S"))
# Bwahahahaha.
_time = time.time
time.time = lambda: when
You can’t perform that action at this time.