Skip to content

Instantly share code, notes, and snippets.

Komu Wairagu komuw

View GitHub Profile
@komuw
komuw / wireguard.md
Last active Feb 28, 2020
wireguard problems
View wireguard.md

I'm having trouble setting up wireguard(and packet forwarding).
Both peers are running Ubuntu 19.10

A. Server(Peer 1)

1. The config is as follows:

cat /etc/wireguard/wg0.conf

[Interface]
Address = 10.66.66.1/24, fd42:42:42::1/64
@komuw
komuw / go_errors_with_stacktrace.go
Created Nov 9, 2019
Golang errors with stack traces
View go_errors_with_stacktrace.go
package main
import (
"fmt"
"runtime"
"strconv"
"strings"
)
/*
@komuw
komuw / BreachHandler.py
Last active Aug 24, 2019
create a breach handler for python's standard logging library
View BreachHandler.py
import time
import logging
import collections
# Inspired by; https://tersesystems.com/blog/2019/07/28/triggering-diagnostic-logging-on-exception/
# Also see; https://docs.python.org/3.6/library/logging.handlers.html#logging.handlers.MemoryHandler
# Also see; https://github.com/komuw/naz/blob/e0666550396400f86b9a547932bb9075c520a5d9/naz/log.py#L159-L230
class BreachHandler(logging.StreamHandler):
"""
Log handler that buffers logs in an in-memory ring buffer until a trigger.
@komuw
komuw / instance_creator.py
Last active Jun 19, 2019
python create a new class instance inside same class
View instance_creator.py
import copy
# see: https://stackoverflow.com/questions/13260557/create-new-class-instance-from-class-method
class Animal(object):
request_id = "Original_Animal"
def reproduce(self):
"""
gives birth to new instances of Animal
@komuw
komuw / print_array_list.zig
Created May 15, 2019
we can print a buffer but not ArrayList
View print_array_list.zig
const std = @import("std");
const warn = std.debug.warn;
pub fn main() !void {
// 1. This works
var buf = try std.Buffer.init(std.debug.global_allocator, "");
defer buf.deinit();
try buf.append("hello");
warn("buffer:\n\t {}", buf);
@komuw
komuw / read_file.zig
Last active May 15, 2019
read a file in zig
View read_file.zig
const std = @import("std");
const os = std.os;
const warn = std.debug.warn;
pub fn main() !void {
var file = try os.File.openRead("/path/to/file.txt");
defer file.close();
const file_size = try file.getEndPos();
// why cant I use?
@komuw
komuw / iterable.py
Created Mar 22, 2019
convert list to iterable
View iterable.py
import asyncio
import collections
class Iterable:
def __init__(self, my_list):
self.pool = collections.deque(my_list, maxlen=None)
self.len = len(self.pool)
self.index = 0
@komuw
komuw / client.go
Last active Jan 4, 2019
client and server odd behaviour
View client.go
package main
import (
"bytes"
"io"
"log"
"net"
"time"
)
@komuw
komuw / blocking_async.py
Created Nov 25, 2018
calling blocking code in async code
View blocking_async.py
import asyncio
import requests
import concurrent
import functools
loop = asyncio.get_event_loop()
def reqq(timeout):
You can’t perform that action at this time.