Skip to content

Instantly share code, notes, and snippets.

alias t='docker-compose run --no-deps --rm web python manage.py test'
alias init_db='docker-compose run --no-deps --rm web python manage.py init_db'
alias drop_db='docker-compose run --no-deps --rm web python manage.py drop_db'
alias shell='docker-compose run --no-deps --rm web python manage.py shell'
@jorotenev
jorotenev / dates.py
Created May 14, 2016 19:00
Snippet to print all dates, given some boundaries
import datetime
# m/d/y
StartDate = "2/12/16"
EndDate = "5/13/16"
date = datetime.datetime.strptime(StartDate, "%m/%d/%y")
dates = [date]
endDate = datetime.datetime.strptime(EndDate, "%m/%d/%y")
@jorotenev
jorotenev / play.c
Last active November 13, 2016 14:34
example3.c from "smashing the stack for fun and profit"
#include <stdio.h>
#include <string.h>
void function(int a, int b, int c) {
char buffer1[5];
char buffer2[10];
int *ret;
ret = buffer1 + 12;
(*ret) += 8;
}
@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))
@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 / 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 / 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 / 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
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 / 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')