Skip to content

Instantly share code, notes, and snippets.

@vlcinsky
vlcinsky / pyproject.toml
Created October 18, 2021 12:13
pyproject.toml generated by poetry v1.1.11 under python 3.10. Pytest version is obsolete (5.2 while v6.2.5 exists and works under python 3.10)
[tool.poetry]
name = "pytestver"
version = "0.1.0"
description = ""
authors = ["Jan Vlcinsky <jan.vlcinsky@tamtamresearch.com>"]
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.dev-dependencies]
@vlcinsky
vlcinsky / pyproject.toml
Created October 8, 2020 14:29
pyproject.toml for newly created project jinjatest
[tool.poetry]
name = "jinjatest"
version = "0.1.0"
description = ""
authors = ["Jan Vlcinsky <jan.vlcinsky@tamtamresearch.com>"]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
@vlcinsky
vlcinsky / test_s3_json_bucket.py
Created June 14, 2020 10:45
S3JsonBucket to dump/load data to S3 bucket. Comment to https://stackoverflow.com/a/50101751/346478
import json
import boto3
class S3JsonBucket:
def __init__(self, bucket_name):
self.bucket = boto3.resource("s3").Bucket(bucket_name)
def load(self, key):
import os
def task_one():
def create_cmd_string(a, b, target):
return "echo a: %s b: %s > %s" % (a, b, target)
with open("list_of_input_filenames.txt") as f:
fnames = [line.strip() for line in f.readlines() if line]
for a in fnames:

Keybase proof

I hereby claim:

  • I am vlcinsky on github.
  • I am vlcinsky (https://keybase.io/vlcinsky) on keybase.
  • I have a public key ASCnbRr-ve9t3Vb2dPBwo8lMftVKos2jXs4Q6PlcgfZw4go

To claim this, I am signing this object:

@vlcinsky
vlcinsky / app.py
Created May 14, 2014 12:49
web.py based web server serving data to clients in streaming manner
import web
import time
urls = (
"/", "streamer",
)
app = web.application(urls, globals())
class streamer:
@vlcinsky
vlcinsky / csv2sql.py
Created April 29, 2014 05:53
Convert CSV file into SQL script
"""
Usage:
csv2sql.py [--table <tablename>] <csvfile>
Options:
--table <tablename> Name of table in database to import into [default: mytable]
Convert csv file with iperf data into sql script for importing
those data into MySQL database.
"""
@vlcinsky
vlcinsky / placfun.py
Created March 18, 2014 23:09
Create annotated function preserving original function intact
""" A study, how to create plac annotated command line script from bare function
preserving original function intact.
This is sometime needed, when the same function is used for call e.g. by a celery,
and for manual testing it is handy to have it in command line version.
Usually, the code (producing only annotated command line tool) looks like::
import plac
@vlcinsky
vlcinsky / age_in_minutes.py
Created October 4, 2011 12:21
calculate_age_in_minutes explained
def calculate_age_in_minutes(rec_time, pub_time):
"""
pub_time .. string with datetime in ISO 8601 format. Time, when is the feed published (mostly current time).
rec_time .. string with datetime in ISO 8601 format. Time, when record was created.
sample ISO string: 2011-10-25T13:55:42.123Z
return .. integer with duration between pub_time and rec_time expressed in minutes
"""
#parsing pub_time to datetime structure. Ignoring timezone and fractions of seconds
pub_t = datetime.datetime.strptime(pub_time[:19],"%Y-%m-%dT%H:%M:%S")
@vlcinsky
vlcinsky / bucketlistresultset.py
Created September 18, 2011 21:13
Modified boto to overcome shortened listing of object versions in AWS S3 problem
def versioned_bucket_lister(bucket, prefix='', delimiter='',
key_marker='', version_id_marker='', headers=None):
"""
A generator function for listing versions in a bucket.
"""
more_results = True
k = None
while more_results:
rs = bucket.get_all_versions(prefix=prefix, key_marker=key_marker,
version_id_marker=version_id_marker,