Skip to content

Instantly share code, notes, and snippets.

@jorotenev
jorotenev / alarm-creator-cloudfront.py
Last active March 29, 2019 11:53
Use a custom version of boto3 in AWS Lambda. Handy when a zip was deployed to Lambda containing a specific version of boto3. Without this, the default boto3 will be used because of the PATH env var precedence. this snippet would insert the current directory of the file to the path (assuming he snippet is in a file in the root of the project cont…
import os, logging, sys
if os.getenv('LAMBDA_TASK_ROOT', None): # check if we are in lambda
# add the current folder to the path of python
# assumes that during build time we installed in the current folder packages from a, say, requirements.txt
# we need this so that our packages are found before the already existing ones in the lambda environment
print("setting the path when in lambda")
curr_file_dir_path = os.path.dirname(os.path.abspath(__file__))
print(curr_file_dir_path)
sys.path.insert(0, curr_file_dir_path)
@jorotenev
jorotenev / tasks.json
Created February 20, 2019 12:57
VS Code Task for AWS CloudFormation validate-template
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "validate-template",
"type": "shell",
"windows": {
"command": "aws"
@jorotenev
jorotenev / readme.md
Created February 11, 2018 14:43
NativeScript JSON schema validation
@jorotenev
jorotenev / example.ts
Created October 29, 2017 21:19
Comparing the different ways of defining a method in TypeScript and their effect on `this`
class SomeClass {
public a;
public b;
constructor() {
this.a = '1';
this.b = []
}
one = () => {
console.log(`one = () => {} ${this.a}`)
this.b.push('one')
def print_object_attrs(obj):
print("%s:" % obj.__name__)
for name, value in [(v, getattr(obj, v)) for v in obj.__dict__ if not v.startswith('__')]:
print("%s=%s" % (name, value))
@jorotenev
jorotenev / datetime_range.py
Last active April 11, 2017 16:50
A simple way to simulate the range() function when using datetime
from datetime import datetime as dt, timedelta as td
def datetime_range(start, end, step):
assert end >= start, "The end date should be after in time than the start. End: {end} Start:{start}".format(end=end,
start=start)
i = 0
@jorotenev
jorotenev / workflow.md
Last active July 26, 2019 09:37
Workflow for git subtree
./thesis
├── docker-compose.yaml
├── micrsoserviceX
├── micrsoserviceY
├── memory-engine

Subtree workflows

Adapted from here. Below is an executive summary for the use case of a university collaborative thesis project.

@jorotenev
jorotenev / find_me_a_site.py
Created March 24, 2017 15:44
Given a list of domains in a csv file, try to find the websites which pass a given predicate.
import threading
from requests import get
import queue
from datetime import datetime as dt
# Given a csv file with domain names, retrieve the content of the webpage, and given a predicate, add the domain name to a result set if the
# response from the passes the check of the predicate.
# Results are written to a timestamped file in the same directory of the script.
### Predicates
# Given a requests.Response object return True if the URL should be added to the result
@jorotenev
jorotenev / test.py
Last active February 11, 2017 00:32
Example of using mixins to make python tests more flexible. Particular interest in order of execution of setUp and setUpClass
import unittest
from unittest import TestCase
"""
Showcase how to use mixins and multiple inheritance to write tests
"""
class BaseTest(TestCase):
"""
A base class to be inheritated by actuall test classes.
"""
def setUp(self): # 3
@jorotenev
jorotenev / cky_algorithm_coordinates.py
Created January 14, 2017 07:39
Small snippet to print the coordinates used in the Cocke–Younger–Kasami CKY algorithm for parsing. The same variable names as in 'Speech and Language Processing by Daniel Jurafsky and James Martin' are used.
j = 8
for j in range(1, j+1): # [1..j] # from 1 to j, including j
for i in range(j-2, 0-1, -1): # from j-2 "downto" 0; including 0
for k in range(i+1, j-1+1): # [i .. j-1] from i to j-1, including j-1
print("(j=%s,i=%i,k=%s)"%(j,i,k))