Skip to content

Instantly share code, notes, and snippets.

View myarik's full-sized avatar
🇺🇦

Yaroslav Muravskyi myarik

🇺🇦
View GitHub Profile
Example infrastructure outage incident report
Friday, May 13, 2077
By the Example Security Team
Earlier this week we experienced an outage in our API infrastructure. Today we’re providing an incident report that details the nature of the outage and our response.
The following is the incident report for the Example Security outage that occurred on April 30, 2077. We understand this service issue has impacted our valued developers and users, and we apologize to everyone who was affected.
@myarik
myarik / struct_custom_unmarshal.go
Created March 23, 2020 09:54 — forked from miguelmota/struct_custom_unmarshal.go
Golang custom struct unmarshal function example
package main
import (
"encoding/json"
"fmt"
"log"
"time"
)
type MyStruct struct {
@myarik
myarik / sliding_window_sort.py
Created November 16, 2017 07:18 — forked from benhoyt/sliding_window_sort.py
Efficient sliding-window sorting of time-series data in CSV file (in Python)
"""Efficient sliding-window sorting of time-series data in CSV file.
Demo for http://stackoverflow.com/a/42398981/68707
Tested on Python 3.5.
"""
import collections
import csv
import datetime
@myarik
myarik / gist:cda2647158001d8d369d
Created November 20, 2015 13:36 — forked from leetreveil/gist:47f8cae575ef7db08cb2
List duplicate celery tasks in redis queues
""" List duplicate celery tasks in redis queues """
import datetime
import redis
import json
import base64
import pickle
from collections import Counter
import argparse
import sys
@myarik
myarik / redis.conf
Last active August 29, 2015 14:16 — forked from joemccann/redis.conf
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
<p>
Two weeks ago I wrote a post called <a href="https://codefisher.org/catch/blog/2015/01/27/python-tips-tricks-and-idioms/">Python: tips, tricks and idioms</a> where I went though a whole lot of features of python. Now however I want to narrow down on just a few, and look at them in more depth. The first is decorators, which I did not cover at all, and the second is context managers which I only gave one example of.
</p>
<p>
There is a reason that I put them together; they both have the same goal. They can both help separate what your trying to do (the "business logic") from some extra code added for clean up or performance etc. (the "administrative logic"). So basically it helps package away in a reusable way code that really we don't care too much about.
</p>
<h2>Decorators</h2>
<p>
Two weeks ago I wrote a post called <a href="https://codefisher.org/catch/blog/2015/01/27/python-tips-tricks-and-idioms/">Python: tips, tricks and idioms</a> where I went though a whole lot of features of python. Now however I want to narrow down on just a few, and look at them in more depth. The first is decorators, which I did not cover at all, and the second is context managers which I only gave one example of.
</p>
<p>
There is a reason that I put them together; they both have the same goal. They can both help separate what your trying to do (the "business logic") from some extra code added for clean up or performance etc. (the "administrative logic"). So basically it helps package away in a reusable way code that really we don't care too much about.
</p>
<h2>Decorators</h2>
<p>
My programming language of preference is python for the simple reason that I feel I write better code faster with it then I do with other languages. However also has a lot of nice tricks and idioms to do things well. And partly as a reminder to myself to use them, and partly because I thought this might be of general interest I have put together this collection of some of my favourite idioms. I am also putting this on <a href="https://gist.github.com/codefisher/9d7993ddbf404c505128">gist.github.com</a> so that anyone that wants to contribute there own things can, and I will try and keep this post up to date.
</p>
<h2>enumerate</h2>
<p>
A fairly common thing to do is loop over a list while also keeping track of what index we are up to. Now we could use a <code>count</code> variable, but python gives us a nicer syntax for this with the <code>enumerate()</code> function.
<script src="https://gist.github.com/codefisher/9d7993ddbf404c505128.js?file=enumerate.py"></script>
@myarik
myarik / __init__.py
Last active August 29, 2015 14:07 — forked from anonymous/__init__.py
# Empty
# API authentication
from social.apps.django_app.utils import strategy
from rest_framework.authtoken.models import Token
from rest_framework.views import APIView
from rest_framework import parsers
from rest_framework import renderers
from rest_framework.authentication import get_authorization_header
from rest_framework.response import Response