Skip to content

Instantly share code, notes, and snippets.

@influentcoder
influentcoder / client.py
Created December 9, 2020 01:12
Echo TCP Server With Epoll
from datetime import datetime
import socket
import sys
import time
def run():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 4444))
msg = "[{}] Hello world!!".format(str(datetime.now())).encode("UTF-8")
@influentcoder
influentcoder / greenlet.py
Created December 8, 2020 22:56
Greenlet Example
"""
Install greenlet before running this: pip install greenlet
"""
from greenlet import greenlet
class GUIFramework:
"""
This class simulates a GUI framework, that has its own main loop.
For simplicity, the loop is just waiting for user input from stdin, and when a key
is pressed, a user-defined callback is invoked.
@influentcoder
influentcoder / interview-questions.md
Last active May 18, 2019 09:22
Interview Questions

Apples and Orange problem

In front of you are 3 boxes. One box contains only apples, another box contains only oranges, and the last contains both apples and oranges. The first box has the label "apples," the second "oranges," and the third "apples and oranges." Unfortunately all of the labels are wrong. Your job is to fix the labels. You are not allowed to peek inside any of the boxes. But you can ask for a sample from any box. You point to a box, and you get a fruit from that box. What is the minimum number of samples you need to label all of the boxes correctly?

http://mkcohen.com/saturday-puzzle-9-apples-and-oranges

@influentcoder
influentcoder / create-debian-package-python.md
Created March 22, 2019 01:28
Creating a Debian package from scrath for a Python library
@influentcoder
influentcoder / groups.md
Created March 13, 2019 13:36
Magma, Semigroups, Monoids, Groups

Summary

Closure Associativity Identity Invertibility
Magma Required
Semigroup Required Required
Monoid Required Required Required
Group Required Required Required Required

Magma

@influentcoder
influentcoder / ml.rst
Last active June 29, 2018 16:34
ML Stuff

Data

Data are observation of real-world phenomena. E.g. stock market data might involve observations of daily stock prices, announcements of earnings by individual companies, opinion articles from pundits.

Tasks

Data can help us answer some questions. E.g. which stocks should I invest in? The tasks are how we get to the answers.

GPG Cheat Sheet

Generate a new key

$ gpg --gen-key
Please select what kind of key you want:
@influentcoder
influentcoder / conftest.py
Created January 23, 2018 15:36
Test against an external processes with dependencies, with pytest-xprocess
import sys
import py
import pytest
from xprocess import ProcessStarter
from servers import ItalicTCPHandler, EchoTCPHandler
python_executable_full_path = sys.executable
python_server_script_full_path = py.path.local(__file__).dirpath("servers.py")
@influentcoder
influentcoder / echo_server.py
Last active January 23, 2018 16:12
Test against an external process with pytest-xprocess
import socketserver
import sys
import time
class EchoTCPHandler(socketserver.StreamRequestHandler):
def handle(self):
data = self.rfile.readline().strip().decode('UTF-8')
print('[ECHO SERVER] Received data: {}'.format(data))
self.wfile.write('Echo: {}'.format(data).encode('UTF-8'))