Skip to content

Instantly share code, notes, and snippets.

@selimslab
selimslab / face_recognition.py
Created May 23, 2020 11:43
this server recognize a person in photos after just seeing a single photo of the person
"""
this server recognize a person in photos after just seeing a single photo of the person
"""
import face_recognition
import os
import pickle
from flask import Flask, jsonify, request
from requests.exceptions import RequestException, Timeout, ConnectionError
from io import BytesIO
"""
Machine Learning model to predict the genres of a movie from its summary
"""
import os
import pickle
from io import StringIO
from flask import Flask, request
from sklearn.preprocessing import MultiLabelBinarizer
import os
from flask.json import JSONEncoder
import datetime
class CustomJSONEncoder(JSONEncoder):
"Add support for serializing time"
def default(self, o):
@selimslab
selimslab / server.py
Last active May 23, 2020 19:16
a concurrent web server in 100 lines, using UNIX fork() syscall, following https://ruslanspivak.com/lsbaws-part1/
# coding: utf-8
"""
a simple concurrent web server
socket -> bind -> listen -> accept -> loop
"""
import socket
import os
import time
import signal
@selimslab
selimslab / lis.py
Last active December 8, 2021 12:37
Peter Norvig's lis.py studied, commented, and modified
"""
Lispy: Scheme Interpreter in Python
Peter Norvig's lis.py studied here
http://norvig.com/lispy.html
The beauty of Scheme is that the full language only needs 5 keywords and 8 syntactic forms.
In comparison, Python has 33 keywords and 110 syntactic forms,
and Java has 50 keywords and 133 syntactic forms.
@selimslab
selimslab / search.py
Last active August 10, 2023 14:59
a search engine in 200 lines
import re
import math
import operator
import logging
from collections import defaultdict, Counter
import numpy as np
class Tokenizer:
def __init__(self, stop_words, ):
@selimslab
selimslab / async-crawler.py
Last active May 10, 2020 18:06
a concurrent crawler in 100 lines
import asyncio
import logging
import collections
import urllib.parse
from pprint import pprint
import aiohttp
import bs4
class AsyncCrawler:
@selimslab
selimslab / 0-structs.c
Last active December 6, 2020 12:10
a garbage collector, replicating https://github.com/munificent/mark-sweep
#include <stdio.h>
#include <stdlib.h>
#define STACK_MAX 256
typedef enum
{
OBJ_INT,
OBJ_PAIR
} ObjectType;
@selimslab
selimslab / hashmap.c
Last active September 9, 2022 11:44
a hash map implementation in C, inspired by https://github.com/jamesroutley/write-a-hash-table
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
typedef struct {
char* key;
char* value;
} key_value_pair;
@selimslab
selimslab / blockchain.py
Last active August 10, 2023 14:59
a simple blockchain in 100 lines
import time
import hashlib
import uuid
import random
from dataclasses import dataclass
from typing import List
@dataclass
class Node:
uid: str