Skip to content

Instantly share code, notes, and snippets.

red_1 red_2 red_3 red_4 red_5 red_6 red_7 red_8 blue_1 blue_2 blue_3 blue_4 blue_5 blue_6 blue_7 blue_8
X 8.06 19.7 25.2 -19.5 -13.3 -2.2 25.3 0 -78.2 -2.2 -54.9 8.3 33.9 -42.8 -39.0 0
Y 1465.7 1505.5 1462.2 1476.8 1435.9 1402.9 1361.6 0 1500.1 1483.2 1446.9 1423.3 1.33.5 1372.6 1433.6 0
Thrown 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
In Play 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0
from logging import Handler
import logging
"""
Usage:
@log_handler.on_error()
def main_function():
log.debug("You won't see this until later")
log.info("You'll see this immediately")
@mikhail
mikhail / README.md
Last active June 13, 2019 00:38
Python Generators and Yielding

Python Generators and Yielding

In python yield can be used to transfer information in both directions.

yield 'hello'

will generate (vs return) the string "hello", whereas

@mikhail
mikhail / class.mysql.php
Created May 13, 2019 20:41
MySQL abstraction library
<?php
define('POSITIVE', 1);
define('NEGATIVE', -1);
define('DB_CONFIG_FILE', '/path/to/mysql.json');
/* MySQLi module does not have this function by default */
function mysqli_field_name($result, $field_offset) {
$properties = mysqli_fetch_field_direct($result, $field_offset);
return is_object($properties) ? $properties->name : null;
}
@mikhail
mikhail / elo_for_ping_pong.py
Last active August 8, 2018 00:21
Elo for ping pong
ELO_DEFAULT = 1500
ELO_K_FACTOR = 16
def expected(Ra, Rb):
# https://en.wikipedia.org/wiki/Elo_rating_system
Ea = (1.0 / (1.0 + pow(10.0, (Rb-Ra)/400.0)))
return Ea, 1-Ea
@bot.add_command('!challenge')
@gen.coroutine
In [1]: b = object()
In [2]: import json
In [3]: json.dumps(b)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-8c425ddada75> in <module>()
----> 1 json.dumps(b)
@mikhail
mikhail / pal_power.py
Created April 17, 2018 18:00
Palindrome power
def is_pal(some_int):
reverse = list(str(some_int))
reverse.reverse()
reverse = int(''.join(reverse))
return some_int == reverse
def main():
start = 999
@mikhail
mikhail / Dockerfile
Created November 12, 2016 17:37
Private alphabot docker file
FROM python:2.7
MAINTAINER Mikhail Simin
ENV USE_REDIS true
ENV USE_SLACK true
ADD alphabot /app/alphabot
RUN pip install -e /app/alphabot
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
@mikhail
mikhail / README.md
Last active January 29, 2016 22:38
Quick handling of python's virtualenv

The two functions (akt and mkvin) in this gist allow for a quick way to create end activate python's virtual environments

mkvin will create a new virtual environment in $HOME/virtualenvironments directory with the name of the directory you're in.

For example:

[mikhail@MadRussian git]$ mkdir projectzero
[mikhail@MadRussian git]$ cd projectzero
[mikhail@MadRussian projectzero]$ mkvin
@mikhail
mikhail / README.md
Last active November 24, 2015 18:58
Bash scripts for backing up mysql to s3 and restoring specific tables from that backup.

Backup & Restore MySQL <-> AWS S3

Based on https://gist.github.com/2206527 this script loops through databases and tables and creates individual files that are uploaded to S3.