Skip to content

Instantly share code, notes, and snippets.

View bmwant's full-sized avatar
🇺🇦
Hold strong Ukraine

Misha Behersky bmwant

🇺🇦
Hold strong Ukraine
View GitHub Profile
@bmwant
bmwant / watch.py
Created May 14, 2015 11:22
Watchdog monitoring on editing python-scripts
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
class ScriptModifiedHandler(PatternMatchingEventHandler):
patterns = ['*.py']
def __init__(self):
super(ScriptModifiedHandler, self).__init__()
@bmwant
bmwant / nginx.conf
Last active August 29, 2015 14:26
php-cgi with nginx on windows
# in block server
location / {
root D:/project/www;
try_files $uri $uri/ /index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root D:/project/www;
fastcgi_pass 127.0.0.1:9000;
@bmwant
bmwant / naive_deployer.py
Created September 29, 2015 12:53
Fabric copyfiles
# -*- coding: utf-8 -*-
import os
from fabric.api import env, run, put, cd, local
env.user = ''
env.password = ''
env.hosts = ['127.0.0.1']
env.shell = "bash -c"
@bmwant
bmwant / reverse_linked_list.py
Created November 11, 2015 10:36
Reverse linked list both iteratively and recursively
class LinkedList(object):
def __init__(self):
self.head = None
self.tail = None
def add(self, node):
if self.tail is not None:
self.tail.next = node
self.tail = node
else:
@bmwant
bmwant / os_info.py
Last active November 15, 2015 12:28
Get some OS info with psutils
import os
import time
import psutil
import humanfriendly
now = time.time()
pid = os.getgid()
ppid = os.getppid()
@bmwant
bmwant / timetable.py
Created December 8, 2015 13:18
Rooms and timetable problem
timetable = (
('10:30', '11:30'),
('10:00', '11:00'),
('11:00', '12:00'),
('09:33', '12:00'),
('17:00', '19:00'),
('17:00', '19:00'),
('17:00', '19:00'),
('17:00', '19:00'),
@bmwant
bmwant / distance.py
Created December 8, 2015 13:19
Find least distance between two words in text
import math
from collections import defaultdict
words = ('the', 'quisck', 'brown', 'fox', 'quick')
class WordDistanceFinder(object):
def __init__(self, words):
@bmwant
bmwant / try_boto.py
Created December 14, 2015 09:37
AWS boto3 some calls
# Setup docs: http://boto3.readthedocs.org/en/latest/guide/quickstart.html
import boto3
# List all regions
client = boto3.client('ec2')
regions = client.describe_regions()['Regions']
for region in regions:
print('Name: %s. Endpoint: %s' % (region['RegionName'], region['Endpoint']))
@bmwant
bmwant / letters_distance.py
Created January 25, 2016 16:54
Find distance between strings based on non-equal characters count
from collections import Counter
def find_letter_distance(string, other):
string_counter = Counter(string)
other_counter = Counter(other)
unique_symbols = set(string + other)
distance = 0
for char in unique_symbols:
@bmwant
bmwant / custom_json_encoder.py
Last active April 10, 2016 12:13
Custom JSON Encoder for own type
import json
from json import JSONEncoder
class Custom(object):
def serialize(self):
return 42
class CustomEncoder(JSONEncoder):