Skip to content

Instantly share code, notes, and snippets.

import time
from urllib2 import urlopen, quote
import json
def fetch_comments(after=None):
url = "http://reddit.com/comments.json"
if after:
url += "?after={0}".format(quote(after))
#print "... Fetching {0} ...".format(url)
@chromakode
chromakode / trekbot.js
Last active March 9, 2020 19:29
A star trek questions Discord bot using Wavenet TTS
const fs = require('fs').promises
const sample = require('lodash/sample')
const intoStream = require('into-stream')
const Discord = require('discord.js')
const textToSpeech = require('@google-cloud/text-to-speech')
const tts = new textToSpeech.TextToSpeechClient()
function waitFor(emitter, event) {
return new Promise(resolve => emitter.once(event, resolve))
@chromakode
chromakode / saved.js
Created June 22, 2011 03:40
Fetch saved links from reddit. Paste into a web browser's JavaScript console to run. Make sure you enable popups.
(function(cb, after, saved) {
var next = arguments.callee
console.log("Requesting after", after)
$.getJSON('http://www.reddit.com/saved/.json', {after:after}, function(data) {
saved = (saved || []).concat(data.data.children)
if (data.data.after) {
console.log('Fetched:', saved.length)
next(cb, data.data.after, saved)
} else {
cb(saved)

Keybase proof

I hereby claim:

  • I am chromakode on github.
  • I am chromakode (https://keybase.io/chromakode) on keybase.
  • I have a public key ASCluTVDeOcCBkDGS7RVqebTOEGGFu4_jLnJdglEDhJ08wo

To claim this, I am signing this object:

console.log('it works!')
@chromakode
chromakode / run_reddit.sh
Created May 1, 2012 21:14
Start reddit in a chroot
#!/bin/bash
#
# Max's groovy chroot script
#
# Install Ubuntu Natty via debootstrap and then run Neil's install script.
# Then adjust the bind mounts to suit your personal locations for the reddit code.
#
if mount | grep -q reddit
then
mgood@capstone11 ~/D/c/b/boots.mgood> boots -H capstonedd -l python
Boots (v0.2.0)
capstonedd:3306 (server v2009.11.1220)
> from boots.api import constructors
> @constructors.register('reverse')
+ def reverse():
+ from boots.api.nodes.node import SyncNode
+ from boots.api.api import Rows
+ def reverse_data(data):
+ return Rows((("".join(reversed(field)) if isinstance(field,basestring) else field
# <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
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
@chromakode
chromakode / header_nanny.py
Created February 20, 2010 22:52
A somewhat scary header munger. You'd better have good version control!
#!/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"#!.+")