Skip to content

Instantly share code, notes, and snippets.

View daboross's full-sized avatar

Dabo daboross

View GitHub Profile
// This method returns whether or not the server supports UUIDs
private boolean supportsUuids() {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
// Get full package string of CraftServer.
// org.bukkit.craftbukkit.versionstring (or for pre-refactor, just org.bukkit.craftbukkit
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
if (version.equals("craftbukkit")) {
return false;
}
String[] split = version.split("_");
from fnmatch import fnmatch
from time import time
from util import hook
class TokenBucket(object):
"""An implementation of the token bucket algorithm.
>>> bucket = TokenBucket(80, 0.5)
[2014-08-26][20:42:47][INFO] [freenode] >> PRIVMSG DogeWallet :balance
[2014-08-26][20:42:47][INFO] [freenode:dogewallet] <DogeWallet> 458.0
[2014-08-26][20:42:47][INFO] [freenode] >> PRIVMSG #doge-coin :.soak 35
[2014-08-26][20:42:48][INFO] [freenode:dogewallet] <DogeWallet> Not enough doge.
[2014-08-26][20:42:48][INFO] [freenode] >> PRIVMSG #doge-coin :Soak failed: Not enough doge.
[2014-08-26][20:42:48][INFO] [freenode] >> PRIVMSG DogeWallet :active
[2014-08-26][20:42:49][INFO] [freenode:dogewallet] <DogeWallet> Active Shibes: 11
[2014-08-26][20:42:49][INFO] [freenode] >> PRIVMSG #doge-coin :My active count: 13, DogeWallet's active count: 11
/*
* Copyright (C) 2013-2014 Dabo Ross <http://www.daboross.net/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
File "cloudbot/__main__.py", line 93, in <module>
main()
File "cloudbot/__main__.py", line 65, in main
restart = cloudbot.run(loop)
File "/home/daboross/Projects/Python/CloudBot/cloudbot/bot.py", line 109, in run
loop.run_until_complete(self._run(loop))
File "/usr/lib/python3.4/asyncio/base_events.py", line 208, in run_until_complete
return future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 243, in result
raise self._exception
@daboross
daboross / events.py
Created June 16, 2014 01:45
Concise example
class BaseEvent:
def __init__(self, bot=None, conn=None, hook=None, base_event=None):
self.bot = bot
self.conn = conn
self.hook = hook
if base_event is not None:
# We're copying an event, so inherit values
if self.bot is None and base_event.bot is not None:
self.bot = base_event.bot
@daboross
daboross / migrateit.py
Last active August 29, 2015 14:02
<3 python
import codecs
import glob
import re
regex = re.compile(re.escape("@hook.command([") + "([^\]]*)" + re.escape("]") + "(:?, (.*))?" + re.escape(")"))
def main():
files = glob.iglob("plugins/*.py")
for path in files:
main() {
local -r FUNCTION="$1"
case "$FUNCTION" in
function-1)
function_1 ;;
function-2)
function_2 ;;
function-2)
function_3 ;;
help)
@daboross
daboross / test.md
Last active August 29, 2015 14:01
TypeError: send() takes 2 positional arguments but 3 were given

I've created test.py as a self contained example demonstrating the problem I am facing.

In the application I am working on, I have an asyncio.Queue object, in which I put tuples of (asyncio.Future, dict).

However, whenever executing this code using PYTHONASYNCIODEBUG=1, I get a strange error on the queue.get() method.

Here's the error on the test.py script:

$ PYTHONASYNCIODEBUG=1 ./test.py 
Traceback (most recent call last):