Skip to content

Instantly share code, notes, and snippets.

@endofline
endofline / rsws-banned.py
Last active July 24, 2017 02:46
really simple web server (rsws) serving singlepage.html
#!/usr/bin/python
import logging
logging.basicConfig(filename='rsws.log',level=logging.DEBUG)
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class S(BaseHTTPRequestHandler):
def _set_headers(self):
@endofline
endofline / unittest_reportresource.py
Last active April 20, 2017 08:00
hangoutsbot cpu usage logger
import asyncio
import logging
import time
import os
logger = logging.getLogger(__name__)
import plugins
@endofline
endofline / test_a.py
Created February 15, 2017 14:37
subverting imported libraries
# test_a.py
# in the bot, this represents the new hangups library
this_is_a_constant = 'ABCD'
def print_constant():
print(repr(this_is_a_constant))
@endofline
endofline / unittest_memoryusage.py
Created July 26, 2015 11:25
Rough Memory Usage Estimate for Hangoutsbot
import logging, os, sys, resource
import psutil # pip3 install psutil
import plugins
logger = logging.getLogger(__name__)
@endofline
endofline / example_presence.py
Created July 19, 2015 12:13
Hangoutsbot Watermark & Typing Fragment
import datetime, time
import hangups
import plugins
def _initialise(bot):
plugins.register_admin_command(["watermark", "typing"])
def watermark(bot, event, *args):
@endofline
endofline / testing_logging.py
Created July 8, 2015 03:10
[hangoutsbot] stream handler example to dump all logs straight to stdout
import sys, logging
def _initialise(bot):
consoleHandler = logging.StreamHandler(stream=sys.stdout)
format = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
consoleHandler.setFormatter(format)
rootLogger = logging.getLogger()
rootLogger.addHandler(consoleHandler)
@endofline
endofline / testing_convmem.py
Created July 2, 2015 07:48
Conversation Memory (Alpha)
import datetime
import plugins
from hangups.ui.utils import get_conv_name
convmem = {}
def _initialise(bot):
_memory_load(bot)
@endofline
endofline / convtools_public.py
Last active August 29, 2015 14:24
Conversation Tools: Public Channels (Proof of Concept)
import hangups
import plugins
def _initialise(bot):
plugins.register_user_command(["public"])
def public(bot, event, *args):
"""list all available public channels when called without any parameters.
to join a channel, call this command with the desired channel number"""
@endofline
endofline / example_modern.py
Created April 21, 2015 09:45
functionally-identical hangouts bot plugins (version 2.4 and above)
"""standard plugin
more documentation: __wikilink__
"""
import plugins
def _initialise(bot):
plugins.register_admin_command(["noop_standard"])
plugins.register_handler(_handle_nothing)
@endofline
endofline / wolframalpha.py
Created March 16, 2015 12:21
Experimental Wolfram Alpha Plugin based on billius's original gist
"""
simple "ask" function for wolfram alpha data
* pip3 install wolframalpha
* get API KEY from http://products.wolframalpha.com/developers/
* put API KEY in config.json:wolframalpha-apikey
"""
import wolframalpha
_internal = {}