Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
# coding: utf-8
import urllib2
import sys
import random
import re
import threading
request_counter = 0
flag = 0
@yanmhlv
yanmhlv / gist:5612256
Created May 20, 2013 13:34
nginx proxy_cache
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:5m max_size=1000m;
server {
listen 80;
server_name cache.example.ru;
# кешируемый адрес
location / {
# кеш включен по умолчанию
set $no_cache "";
# отключаем кеш для всех методов, кроме GET и HEAD
if ($request_method !~ ^(GET|HEAD)$) {
# coding: utf-8
from mongoengine import *
import random, string
import minimongo as mm
from pymongo import MongoClient
class MongoEngine_Model1(DynamicDocument):
a = StringField()
meta = {'collection': 'test'}
@yanmhlv
yanmhlv / gist:6041988
Created July 19, 2013 20:06
simple mongoengine model connect to mongohq.com
# coding: utf-8
from flask import Flask, request, jsonify
import mongoengine as me
class User(me.Document):
email = me.EmailField(required = True)
register_at = me.DateTimeField(required = True)
activation = me.BooleanField()
@yanmhlv
yanmhlv / gist:6177803
Created August 7, 2013 19:45
запуск процесса под админом
import subprocess
subprocess.call(['runas', '/user:Administrator', 'C:/my_program.exe'])
@yanmhlv
yanmhlv / gist:6209562
Created August 12, 2013 09:44
Tornado AsyncHTTPClient
# coding: utf-8
import tornado.ioloop
import tornado.web
import tornado.httpclient
import tornado.autoreload
def handler_request(response):
if response.error:
print response.error
@yanmhlv
yanmhlv / gist:6220164
Created August 13, 2013 11:17
tornado.ioloop.PeriodicCallback
import tornado.ioloop
count = 0
def print_hello():
global count
print(count, "Hello")
count += 1
timer = tornado.ioloop.PeriodicCallback(print_hello, 300)
timer.start()
@yanmhlv
yanmhlv / gist:6220591
Created August 13, 2013 12:25
Launch PyQt4 with tornado
import tornado.ioloop
import tornado.autoreload
from PyQt4 import QtGui
import sys
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.timer = tornado.ioloop.PeriodicCallback(self.printable, 300)
self.timer.start()
@yanmhlv
yanmhlv / gist:6220856
Last active October 21, 2016 19:09
Simple PyQt4 web browser
from PyQt4 import QtCore, QtGui, QtWebKit
import sys
class Browser(QtGui.QMainWindow):
def __init__(self):
"""
Initialize the browser GUI and connect the events
self.html.settings -> QtWebKit.QWebSettings
"""
@yanmhlv
yanmhlv / gist:6221007
Created August 13, 2013 13:21
captcha
# coding: utf-8
from PIL import Image, ImageDraw, ImageFont
from random import randint, choice
import StringIO, string
def captcha():
key = ''.join( [choice(string.ascii_lowercase + string.digits) for i in xrange(5)] )
img = Image.new('RGB', (100,30), 0xffffff )