Skip to content

Commit

Permalink
Only insignificant nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed May 26, 2017
1 parent c2498c4 commit e5213ed
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 58 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
*.bak
*.pyc
.DS_Store
.venv
*.pyo
*.secret
*.swp
*.tmp
*~
.DS_Store
.vagrant/
.venv
__pycache__
github_pat.secret
19 changes: 6 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Opening a PR
Once you open a pull request, ChaosBot will give it X seconds (where X is
determined by github\_api.voting.get\_voting\_window)
before collecting votes. During this time, you should let people know about
your contribution, so that they may vote for it and ensure your hard work gets
merged in. If you do not wish for ChaosBot to consider your PR for merging just
yet, add "WIP" somewhere in your PR title. Remove it when you're ready for voting.

Once you open a pull request, ChaosBot will give it X seconds (where X is determined by github\_api.voting.get\_voting\_window) before collecting votes. During this time, you should let people know about your contribution, so that they may vote for it and ensure your hard work gets merged in. If you do not wish for ChaosBot to consider your PR for merging just yet, add "WIP" somewhere in your PR title. Remove it when you're ready for voting.

# Changing your PR
You may change your PR at any time without losing votes, but keep in mind, any
new changes will reset the vote window for additional time.

You may change your PR at any time without losing votes, but keep in mind, any new changes will reset the vote window for additional time.

# Merging your PR
At the end of the voting window, ChaosBot will review the votes, and if your PR
crosses a threshold, your changes will be merged in. To thank you for your merged
contribution, ChaosBot will then follow you on GitHub. If your changes are not
merged in, take the time to consider the feedback you received, and create a new
PR with changes you believe people will be willing to vote for.

At the end of the voting window, ChaosBot will review the votes, and if your PR crosses a threshold, your changes will be merged in. To thank you for your merged contribution, ChaosBot will then follow you on GitHub. If your changes are not merged in, take the time to consider the feedback you received, and create a new PR with changes you believe people will be willing to vote for.
File renamed without changes.
2 changes: 1 addition & 1 deletion dev/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# vim: ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
From python:onbuild
31 changes: 10 additions & 21 deletions patch.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
inject some memoize caching into our github api functions. we're keeping the
caching layer separate from the api layer by doing it this way
Inject some memoize caching into our github api functions.
We're keeping the caching layer separate from the api layer by doing it this way.
"""

import inspect
import settings
from os.path import dirname, abspath, join
from functools import partial
import inspect

from memoize import memoize
from memoize.backends import json_backend

import github_api.voting
import github_api.repos

import settings


THIS_DIR = dirname(abspath(__file__))

api_backend = json_backend(join(THIS_DIR, settings.MEMOIZE_CACHE_DIRNAME))

# here we're creating a specialized memoize decorator that ignores the "api"
# argument in a function when constructing the memoize key. we do this because
# "api" is a resource that should not be considered as part of the memoize
# key
api_memoize = partial(memoize, blacklist={"api"}, backend=api_backend)

# a helper for monkey-patch-decorating functions in different modules


def decorate(fn, dec):
"""helper for monkey-patch-decorating functions in different modules"""
mod = inspect.getmodule(fn)
new_fn = dec(fn)
setattr(mod, fn.__name__, new_fn)

cache_dir = join(dirname(abspath(__file__)), settings.MEMOIZE_CACHE_DIRNAME)
api_memoize = partial(memoize, blacklist={"api"}, backend=json_backend(cache_dir))

# now let's memoize some very frequent api calls that don't change often
decorate(github_api.voting.get_vote_weight, api_memoize("1d"))
Expand Down
5 changes: 4 additions & 1 deletion redditchaosbot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import praw
from praw.models import MoreComments
import pprint
from praw.models import MoreComments


'''Authenticated instance of Reddit'''
Expand Down
37 changes: 21 additions & 16 deletions server/server.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import http.server
import socketserver
import socket

# set the process name to "chaos_server" so we can easily kill it with
# "pkill chaos_server"


def set_proc_name(newname):
"""Change the process name using libc.so.6"""
from ctypes import cdll, byref, create_string_buffer
libc = cdll.LoadLibrary('libc.so.6')
buff = create_string_buffer(len(newname) + 1)
buff.value = newname.encode("ascii")
libc.prctl(15, byref(buff), 0, 0, 0)


set_proc_name("chaos_server")

# start server on port 80
PORT = 80
Handler = http.server.SimpleHTTPRequestHandler


class NoTimeWaitTCPServer(socketserver.ThreadingTCPServer):
""" when a socket does is shutdown dance, it ends up in a TIME-WAIT state,
which can prevent rebinding on it quickly. here we say "shut up, socket",
let me rebind anyways even if you're in TIME-WAIT." that will teach it. """
"""When a socket does is shutdown dance, it ends up in a TIME-WAIT state,
which can prevent rebinding on it quickly. Here we say "shut up, socket",
let me rebind anyways even if you're in TIME-WAIT." That will teach it."""

def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)


httpd = NoTimeWaitTCPServer(("", PORT), Handler)
httpd.serve_forever()
def main():
# set the process name to "chaos_server" so we can easily kill it with:
# pkill chaos_server
set_proc_name("chaos_server")

port = 80
handler = http.server.SimpleHTTPRequestHandler
httpd = NoTimeWaitTCPServer(("", port), handler)

# serve HTTP on port 80
httpd.serve_forever()

if __name__ == "__main__":
main()
5 changes: 2 additions & 3 deletions startup.d/40-run-puppet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash

#!/bin/sh
cd puppet
puppet apply --verbose --modulepath=$PWD/modules/ $PWD/manifests/
puppet apply --verbose --modulepath="$PWD/modules/" "$PWD/manifests/"
2 changes: 1 addition & 1 deletion startup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
cd "$(dirname "$0")"

for file in startup.d/*; do
Expand Down
3 changes: 3 additions & 0 deletions utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import os
import logging
Expand Down

0 comments on commit e5213ed

Please sign in to comment.