Skip to content

Instantly share code, notes, and snippets.

View nanvel's full-sized avatar
🇺🇦

Oleksandr nanvel

🇺🇦
View GitHub Profile
@nanvel
nanvel / xmlparser.py
Created June 22, 2014 12:27
Lightweight xml parser
from xml import sax
class XMLParser(sax.handler.ContentHandler):
def __init__(self, keys=[], lists=[], *args, **kwargs):
"""
:param keys: list of data keys have to be available in data
:param lists: list of nodes have be represented as list
@nanvel
nanvel / gist:4f7696174ac3a9b3554c
Created October 31, 2014 14:37
Spike project with Amazon CloudSearch
"""
Search bebop series.
"""
import arrow
import json
from tornado import options
from tornado.httpclient import HTTPError, HTTPClient, HTTPRequest
from tornado_botocore import Botocore
from tvs import TVS
@nanvel
nanvel / tvs.py
Last active August 29, 2015 14:08
Bebop tvs
# -*- coding: utf-8 -*-
TVS = [{
'number': 1,
'title': 'Asteroid Blues',
'airdate': 'October 24, 1998',
'genre': ['anime', 'action'],
'content': """In a flashback, Spike Spiegel is shown waiting near a church holding a bouquet of flowers, before leaving as the church bell rings. As he walks away, images of a gunfight he participated in are shown. In the present, Spike, currently a bounty hunter, and his partner Jet Black head to the Tijuana asteroid colony on their ship, the Bebop, to track down a bounty-head named Asimov Solensan. Asimov is wanted for killing members of his own crime syndicate and for stealing a cache of a dangerous combat drug known as Bloody-Eye. On the colony, Asimov and his girlfriend, Katerina, are ambushed at a bar by his former syndicate while attempting to sell a vial of Bloody-Eye, but Asimov manages to fight his way out by using the drug himself. Spike later encounters Katerina and reveals to her that he is a bounty hunter searching for Asimov; Spike is prompt
@nanvel
nanvel / Search using redis lua scripting vs sql join
Last active August 29, 2015 14:08
Get my friends activities using redis (redis JOIN alternative) code
import os.path
import sqlite3
import redis
import time
import uuid
class RedisSearch(object):
@property
@nanvel
nanvel / s3.py
Created July 24, 2015 14:56
Async s3 uploader for tornado
"""
Async Tornado S3 uploader with AWS4 sign.
https://gist.github.com/stalkerg/63bad3ea49be6268df49
Edited by @nanvel 2015-07-24
Usage example:
.. code-block:: python
@nanvel
nanvel / email_with_attachment.py
Created August 7, 2015 07:00
Send email with attachments using Amazon SES
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import botocore.session
if __name__ == '__main__':
session = botocore.session.get_session()
ses = session.get_service('ses')
@nanvel
nanvel / ddb_table.py
Created September 11, 2015 16:37
DDBTable class for DynamoDB in examples (http://nanvel.com/p/dynamodb)
import botocore.session
import logging
import re
import six
from functools import partial
logger = logging.getLogger()
@nanvel
nanvel / sha256.py
Last active September 28, 2016 12:30
SHA-256, binary
"""
This code has been written just for fun, it is slow and may produce inaccurate results.
The idea was to transition from mathematics to an algorithm.
"""
import binascii
import hashlib
import itertools
@nanvel
nanvel / bitcoinminer.py
Created October 2, 2016 04:45
SHA256 computation for bitcoin
import struct
class Miner():
def __init__(self, previous_hash, transactions_hash, timestamp, bits, nonces):
self.previous_hash = previous_hash
self.transactions_hash = transactions_hash
self.timestamp = timestamp
self.bits = bits
@nanvel
nanvel / bincoinsha256i3.py
Created October 3, 2016 05:49
Bitcoin SHA-256, iteration 3, line by line implementation
w0 = 0x5d218b61
w1 = 0x9ee563e9
w2 = 0x6e3c750e
w3 = 0xbc44ad0e
w4 = 0xcccb8798
w5 = 0x18dcead4
w6 = 0x7dc014d9
w7 = 0xf3ffe957