Skip to content

Instantly share code, notes, and snippets.

View Toshakins's full-sized avatar
👽
experience tranquility

Anton Ovinnikov Toshakins

👽
experience tranquility
View GitHub Profile
@Toshakins
Toshakins / firewall.sh
Last active May 4, 2017 16:10
Redirect ports on OS X El Capitan via embedded firewall
#!/bin/bash
echo "
rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 4443
" | sudo pfctl -ef -
@Toshakins
Toshakins / README.MD
Created July 4, 2017 13:41
Form Checklist
  • All inputs should be accessible via keyboard
  • Form should be accessible without javascript
  • Form should be submitted on 'Enter' hit in a text field.
Schedule
10:00 Stage A
WebVR - The Next Frontier (ENG)
Martin Splitt
11:00 Stage B
Machines Must Suffer (RUS)
Oleksandr Pavlyshch
@Toshakins
Toshakins / Code.gs
Created December 1, 2017 20:49
Spreadsheet notifications
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 50; // Number of rows to process
// Fetch the range of cells A2:B50
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
@Toshakins
Toshakins / scratch.rb
Last active December 27, 2018 10:56
Method Mapping Demo
class Actions
def action_a
puts 'A'
end
def action_b
puts 'B'
end
def action_c
@Toshakins
Toshakins / serializers.py
Created March 19, 2019 09:27
DRF Nested Multipart Example
class NestedSerializer(Serializer):
name = CharField()
...
class UserSerializer(Serializer):
user = JSONField(validators=nested_validator)
...
def nested_validator(value):
serializer = NestedSerializer(data=value)
@Toshakins
Toshakins / architectures.md
Last active February 12, 2020 21:30
FaaS providers thoughts

Architectures

Compute as glue

Glue several services together with FaaS. Example: direct S3 upload triggers a function which invokes Rekognition, after that the result is saved by another function to the DynamoDB.

Backends

Literally the architecture that responds to HTTP calls. Youcan organize it in various ways too.

  • One function for whole service
  • Several functions for the service
@Toshakins
Toshakins / timer.py
Last active May 5, 2020 11:24
Python Benchmark Decorator and Context Manager
import gc
import time
def readable_time():
return time.strftime('%Y %b %d %H:%M:%S +0000',
time.gmtime(time.time()))
class Timer:
def __init__(self, scope):
self.scope = scope or '===='
@Toshakins
Toshakins / __main__.py
Created May 31, 2020 12:10
Event loop inside threads, Python
import asyncio
import concurrent
import threading
from concurrent.futures import as_completed, ThreadPoolExecutor
from itertools import zip_longest
from random import random
async def subwork(i):
slept = random() % 1
await asyncio.sleep(slept)
@Toshakins
Toshakins / dj_redis.py
Created June 12, 2020 21:02
django redis test case
from uuid import uuid4
from django.conf import settings
from django.test import SimpleTestCase
from django.utils.decorators import classproperty
def _generate_record(host, port):
return {