Skip to content

Instantly share code, notes, and snippets.

View vadimii's full-sized avatar

Vadim Gusev vadimii

View GitHub Profile
@vadimii
vadimii / thumbnail1.py
Created February 9, 2014 05:23
Thumbnail and end up with a square image
from PIL import Image
size = (36, 36)
image = Image.open(data)
image.thumbnail(size, Image.ANTIALIAS)
background = Image.new('RGBA', size, (255, 255, 255, 0))
background.paste(
image,
((size[0] - image.size[0]) / 2, (size[1] - image.size[1]) / 2))
@vadimii
vadimii / minmax.py
Last active January 1, 2016 09:39
Min-Max file dates in directory
import os, sys, datetime
maxm = minm = None
for root, dirs, files in os.walk(sys.argv[1] if len(sys.argv) > 1 else '.'):
for name in files:
path = os.path.join(root, name)
mtime = os.path.getmtime(path)
maxm = maxm if maxm and maxm > mtime else mtime
minm = minm if minm and minm < mtime else mtime
@vadimii
vadimii / application.js
Last active December 29, 2015 22:59
Marionette.js form Sublime Text templates
AppManager.module('${1:AppName}App', function (${1:AppName}App, AppManager, Backbone, Marionette, \$, _) {
'use strict'
var controllers = [
createView: function () {
return new Marionette.ItemView({
template: _.template('<p style="color:red">Empty content</p>'),
title: '${2:Неизвестный раздел}',
model: new Backbone.Model()
@vadimii
vadimii / extrans.py
Last active December 25, 2015 00:59
Excel file transformation with python-excel lib
# coding: utf-8
import re
from xlrd import open_workbook
from xlwt import Workbook
def read_workbook():
workbook = open_workbook('PriceObMatLidersb.xls')
for sheet in workbook.sheets():
@vadimii
vadimii / parser.py
Last active December 23, 2015 22:09
Medical standard HTML file parser
# coding: utf-8
import re
from collections import defaultdict
from json import dumps
from glob import glob
from os.path import basename, splitext, join
from lxml import etree
REFLAGS = re.IGNORECASE | re.UNICODE | re.MULTILINE
@vadimii
vadimii / Publisher.groovy
Last active December 20, 2015 23:18
ActiveMQ Publisher class implemented in java and groovy
package amq
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import static amq.Constants.*
class Constants {
static final BROKER_URL = 'tcp://localhost:61616'
}
@vadimii
vadimii / convex.py
Last active December 20, 2015 05:49
Convex combination for Coursera's "Coding the Matrix" course
import time
from vec import Vec
from plotting import plot
def list2vec(l):
D = set(range(len(l)))
return Vec(D, {k: v for k, v in enumerate(l)})
def draw_line(p1, p2):
resolution = 10
@vadimii
vadimii / kule.conf
Last active December 18, 2015 12:19
Run Kule service with upstart and custom python run file
# upstart config /etc/init/kule.conf
description "Kule service for some-ui project"
author "Someone <[email protected]>"
start on runlevel [2345]
stop on runlevel [06]
respawn
exec python /home/admin/services/somekule.py
@vadimii
vadimii / hdout.html
Created June 4, 2013 19:50
HDOut.tv proxy for using alternate video URL and downloading video
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>HDOut &middot; iPhone Proxy</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<a></a>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
@vadimii
vadimii / vimeosync.py
Last active December 17, 2015 20:08
Synchronization of the local MongoDB with Vimeo Channel
import sys
import logging
from math import ceil
from random import random
from datetime import datetime
from pymongo import ASCENDING
from pymongo.mongo_client import MongoClient
from pymongo.errors import OperationFailure