Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
@yanmhlv
yanmhlv / gist:6221018
Created August 13, 2013 13:22
thumbs
#!/usr/bin/env python
# coding: utf-8
from PIL import Image
import sys, os
#@app.route("/thumbs")
def thumbs():
# not good (type of values) but something like this
@yanmhlv
yanmhlv / GoSublime.settings
Last active April 5, 2016 14:32
sublime text 3 config
{
"fmt_cmd": [
"goimports"
],
"autocomplete_closures": true,
"complete_builtins": true,
"comp_lint_enabled": true,
"comp_lint_commands": [
{"cmd": ["golint *.go"], "shell": true},
{"cmd": ["go", "vet"]},
@yanmhlv
yanmhlv / gist:6230422
Created August 14, 2013 12:00
tornado vk auth
#!/usr/bin/env python
#
# Vkontatke OAuth 2.0 wrapper
# Copyright 2011, Adil Khashtamov [[email protected]]
# http://khashtamov.kz
#
#
import logging
@yanmhlv
yanmhlv / gist:6230541
Created August 14, 2013 12:18
tornado http server
import tornado.httpserver
import tornado.web
import tornado.ioloop
def handle_request(request):
message = "You requested %s\n" % request.uri
request.write("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % (
len(message), message))
request.finish()
@yanmhlv
yanmhlv / gist:6248619
Created August 16, 2013 09:52
color output in terminal
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
@yanmhlv
yanmhlv / gist:6256338
Last active December 21, 2015 05:19
ubuntu toram
http://ubuntuforums.org/showthread.php?t=1267853
http://www.pendrivelinux.com/ubuntu-toram-how-to-make-ubuntu-boot-to-ram/
http://reboot.pro/topic/14547-linux-load-your-root-partition-to-ram-and-boot-it/
http://askubuntu.com/questions/275795/customizing-ubuntu-to-run-from-ram-only-within-grub-options
http://askubuntu.com/questions/28671/distro-that-i-can-load-into-ram
@yanmhlv
yanmhlv / gist:6329763
Last active December 21, 2015 15:49
Ubuntu LiveCD env
# root, сначала надо обновить репозиторий,
# /etc/apt/source.list
#deb http://archive.ubuntu.com/ubuntu/ raring main restricted universe multiverse
#deb http://security.ubuntu.com/ubuntu/ raring-security main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu/ raring-updates main restricted universe multiverse
apt-get update
#apt-get -y install apache2-utils
#apt-get -y install tortoisehg mercurial mc htop chromium-browser
apt-get -y install git mercurial mc htop
# coding: utf-8
import collections
import re
buildings = collections.defaultdict(dict)
with open('travian/buildings.txt') as fh:
for line in fh.readlines():
if re.match(r'#\s.', line):
# coding: utf-8
field = [
{'cost': 10, 'prod': 2, 'time': 3},
{'cost': 20, 'prod': 3, 'time': 4}
]
total_resource, base_production, total_time = 0, 1, 0
lvl = 0
required_lvl = len(field)
class BaseHandler(RequestHandler):
COOKIE_SESSION = 'sid'
def get_current_user(self):
sid = self.get_secure_cookie(COOKIE_SESSION)
if not sid:
sid = '%s' % uuid4()
db.sessions.insert({'sid': sid, 'date_created': datetime.datetime.now())
return False
session = db.session.find_one({'sid': sid})
return sid