Skip to content

Instantly share code, notes, and snippets.

View bashkirtsevich's full-sized avatar
:octocat:
bashkirtsevich.github.io

D.A.Bashkirtsev bashkirtsevich

:octocat:
bashkirtsevich.github.io
View GitHub Profile
@bashkirtsevich
bashkirtsevich / asyncio_shutdown_loop.py
Created May 18, 2020 15:43 — forked from nvgoldin/asyncio_shutdown_loop.py
Python 3.5 asyncio - shutdown all tasks safely using signal handler
import signal
import functools
async def looping_task(loop, task_num):
try:
while True:
print('{0}:in looping_task'.format(task_num))
await asyncio.sleep(5.0, loop=loop)
except asyncio.CancelledError:
return "{0}: I was cancelled!".format(task_num)
@bashkirtsevich
bashkirtsevich / gist:b94ab7b12746d317c71fc2300837a023
Created October 12, 2019 07:35 — forked from chrisdone/gist:02e165a0004be33734ac2334f215380e
Build and run minimal Linux / Busybox systems in Qemu

Common

export OPT=/opt
export BUILDS=/some/where/mini_linux
mkdir -p $BUILDS

Linux kernel

@bashkirtsevich
bashkirtsevich / readdisk.py
Created September 29, 2019 10:52 — forked from blaquee/readdisk.py
rawdisk python
import os
import sys
SECTOR_SIZE = 512
def main():
try:
if len(sys.argv) != 4:
raise Exception('Not Enough Arguments')
else:
@bashkirtsevich
bashkirtsevich / listfiles.py
Last active September 29, 2019 10:31 — forked from jonte/listfiles.py
Hack to parse FAT32
# https://www.easeus.com/resource/fat32-disk-structure.htm
import struct
import sys
def getBytes(fs, pos, numBytes):
fs.seek(pos)
byte = fs.read(numBytes)
if (numBytes == 2):
formatString = "H"
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torch.utils.data as data
from torch.autograd import Variable
from tqdm import tnrange, tqdm_notebook, tqdm
"""My attempt at Karpathy's char-rnn from the unreasonableness of RNNs post
@bashkirtsevich
bashkirtsevich / pytorch_gru.py
Created June 24, 2019 18:43 — forked from kenzotakahashi/pytorch_gru.py
PyTorch GRU example with a Keras-like interface.
import numpy as np
from sklearn.model_selection import train_test_split
import torch
import torch.nn as nn
from torch.autograd import Variable
np.random.seed(1337)
MAX_LEN = 30
@bashkirtsevich
bashkirtsevich / debian-strongswan.md
Created April 24, 2019 06:51 — forked from andrewlkho/debian-strongswan.md
Setting up a secure VPN with strongSwan on debian

With heightening concern regarding the state of internet privacy (fuelled in part by the passing of the Investigatory Powers Act in the UK), I have set up a VPN server on the virtual server I have hosted with Mythic Beasts. This uses strongSwan and certificate-based IKEv2 authentication.

Assumptions:

  • Debian Jessie server already set up and accessible via debian.example.com, a public IPv4 of 203.0.113.1 and a public IPv6 of 2001:db8::1
  • Client username of me
  • Clients are running the latest versions of macOS and iOS (Sierra and 10 respectively at the time of writing)
  • No need to support any other operating systems (although the setup is easily translated)

For automated deployment of a similar setup, albeit Ubuntu-based and using ansible for deployment, I recommend you take a look at Algo VPN. I used that project as a basis for my configuration.

@bashkirtsevich
bashkirtsevich / IndexedDB101.js
Created April 16, 2019 08:17
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@bashkirtsevich
bashkirtsevich / connection.py
Created December 17, 2018 15:05 — forked from datakurre/connection.py
Python 3.5 async / await example with HTTP-AMQP -bridge and Nix based development environment
# -*- coding: utf-8 -*-
import aioamqp
connection = None
protocol = None
async def disconnected(exception):
global connection, protocol
@bashkirtsevich
bashkirtsevich / dns_server.py
Created July 17, 2018 15:29 — forked from Phaeilo/dns_server.py
Bare bones Python 3 DNS server
#!/usr/bin/env python3
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors