Skip to content

Instantly share code, notes, and snippets.

View lozhn's full-sized avatar

Nikita Lozhnikov lozhn

View GitHub Profile
@lozhn
lozhn / img_to_pattern.py
Last active December 21, 2015 03:18
Converts all images in a directory with a 600px height pattern. Also script makes 120px height thumbnails. Images name pattern 00.jpg, 01.jpg, ... All thubnails will have the same names but with suffix '_s'(00_s.jpg, 01_s.jpg, ... required http://wand-py.org/ Usage: $ python img-to-pattern.py <path>
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys, wand
from wand.image import Image
if len(sys.argv) > 1 : _path = sys.argv[1]
else : _path = './'
os.chdir(_path)
@lozhn
lozhn / dirs.py
Last active August 29, 2015 14:10
Solves unix limit dir limit. 2012. ITSumma
#!usr/bin/python
import os, os.path, shutil
os.chdir("data")
list_of_dir = [name for name in os.listdir('.') if os.path.isfile(name) or os.path.isdir(name)]
for var in list_of_dir:
if not os.path.exists(var[0:2].upper()) :
@lozhn
lozhn / parse.py
Created November 23, 2014 02:40
Parses to JSON a timetable on baikal-ppk.ru
# -•- coding: utf-8 -•-
import lxml.html
import datetime, time
import json
import requests
import sys
base_url = 'http://baikal-ppk.ru/schedule/'
@lozhn
lozhn / sonets.py
Last active August 29, 2015 14:11
Грабим engshop.ru на предмет всех 154 сонетов Шекспира в ПДФничек и делаем 2 версии : оригинал / оригинал + перевод Маршака
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import lxml.html
import pdfkit
import markdown
base_url = "http://engshop.ru/shekspir-sonet-%i-na_anglieskom/"
options = {
@lozhn
lozhn / app.py
Last active August 29, 2015 14:27
get VK Api Token with bottle
import json
import requests
from bottle import route, run, redirect, request
APP_ID = YOUR APP ID
APP_SECRET = YOUR APP SECRET
SCOPE = YOUR APP SCOPE (e.g. 'photos,groups,offline')
REDIRECT_URI = YOUR APP OPEN API HOST (e.g. 'http://localhost:8080/auth')
TOKEN = ''
@lozhn
lozhn / collage.py
Last active October 6, 2015 12:54
Create collage with several images. Python3 class. PEP-8 compatible.
from PIL import Image, ImageOps
import os
import sys
import glob
PATH = './img/'
IMAGES = glob.glob(PATH+'*.jpg')
COLS = 5
# ROWS = len(IMAGES) / COLS
ROWS = 4
@lozhn
lozhn / model.py
Created March 24, 2017 18:18
DMD course. Base activerecord-like python model.
import datetime
import psycopg2
from collections import namedtuple
"""
Some advices to use Model class for interaction with user_tables
For example we have User class that derived from Model
We will fetch data from table with name __classname__ + 's'
@lozhn
lozhn / remove_stars.js
Last active April 5, 2017 16:08
Run in Chrome JS Console to instantneously click all "Unstar" buttons on your Stars page at https://github.com/{username}?tab=stars (then refresh page due to pagination on run again)
[...document.getElementsByClassName('starred')].map(e => e.children[1].click())
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lozhn
lozhn / right-and-down-challenge.ipynb
Created March 24, 2018 12:00
Right and Down challenge
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.