Skip to content

Instantly share code, notes, and snippets.

View mightymercado's full-sized avatar
🏠
Working from home

ken mightymercado

🏠
Working from home
View GitHub Profile
@mightymercado
mightymercado / worker.py
Last active June 16, 2024 05:25
Send data to a multiprocessing.Process running an asyncio event loop
# A rare scenario: Communicate to a child process that's running an event loop
import asyncio
from asyncio import StreamReader, StreamReaderProtocol
from multiprocessing import Process
import os
class Worker:
def __init__(self):
self.read_fd, self.write_fd = os.pipe()
@mightymercado
mightymercado / binet.py
Created March 13, 2020 05:01
Computing Binet's Formula without Loss
from __future__ import annotations
'''
Unique way of solving fibonacci number.
By computing Binet's formula using integer operations only.
We do this by representing (1 + √5) and (1 - √5) as generalized tuple
representing the sum of an integer and the coefficient of √5.
All tuples would represent a algebraic field under basic arithmetic (+, -, *, /, and pow).
Below I implement this tuple as `binet` class then implement the
operations as class operators.
@mightymercado
mightymercado / refactor.md
Last active March 26, 2020 07:10
Refactoring Todo

Syntax Refactoring

It is advised to use PEP 8 Style Guide.

  1. Python uses snake case variables by default.
  2. Line length should be at most 79. Use \ to break up a line.
    one, two, three, four, five, size, seven, eight, nine, \
        ten, eleven = token.split()
  3. Some files should be broken down into more files because they are too long (e.g. flask/app/utils.py).
@mightymercado
mightymercado / 1332c.md
Last active April 29, 2020 00:34
1322C - Instant Noodles Writeup

Task

Type: Div1C https://codeforces.com/contest/1322/problem/C

Problem

illustration

Given a bipartite graph of n vertices (labelled 1 to N) and m edges. Let L and R be the disjoint set of vertices. Formally, "disjoint" means that there exists no x and y such that x ∈ L and y ∈ R and edge (x, y) exists. Each vertex i has a value c[i].

For all S ∈ L, N(S) is the set of vertices in R adjacent to any vertex in S.

Task

Div2E / Div1C https://codeforces.com/contest/816/problem/E

Given an array C, D, X of length n of positive integers and a integer budget B. You need to sum most number of elements in C such as the sum <= B, but you can optionally apply a coupon D[i] when choosing C[i] so it becomes C[i] - D[i] instead. But in order to be able to apply the coupon for an index i, you need to have used coupon on index x[i].

Initial Intuitions

  1. An implicit graph can be built from the coupon dependencies.
  2. The graph is a tree rooted at 1.
@mightymercado
mightymercado / genyproxy.md
Created June 23, 2020 01:01
Using an HTTP/S proxy with username/password in Genymotion

Install mitmproxy

brew install mitmproxy

Start mitmproxy with an upstream proxy

mitmproxy --mode upstream:https://host:port --upstream-auth=user:password

Create any genymotion android device in bridged network mode

Use 10.0.3.2:8080 as proxy in device

@mightymercado
mightymercado / file1.txt
Created July 15, 2022 15:23
Created via API
Demo
askdmalksd