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
@selimslab
selimslab / pas.py
Last active May 27, 2020 21:31
a simple interpreter in python
"""
Here be dragons
This is a basic interpreter
a computer program is just text. Compilers and interpreters translate this text for the machine
let's say our program is 2 * 7 + 3
1. First step is lexical analysis, a fancy term for tokenizing
@selimslab
selimslab / filters.py
Last active June 7, 2020 18:47
an API to explore mobile user events , built with Django REST, has filter, group, sort, and aggregate
from django_filters.rest_framework import FilterSet
from django_filters import DateFromToRangeFilter
from api.models import Record
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters
class CustomFilter(FilterSet):
date = DateFromToRangeFilter()
@selimslab
selimslab / decodeString.py
Last active October 26, 2020 07:29
String Algorithms
def decodeString(self, s):
"""
s = "3[a]2[bc]", return "aaabcbc".
s = "3[a2[c]]", return "accaccacc".
s = "2[abc]3[cd]ef", return "abcabccdcdcdef".
"""
stack = []; coeff = 0; ans = ''
for c in s:
from fuzzywuzzy import process, fuzz
def match_by_fuzzy_string_search(
possible_matches: List[str], string_to_be_searched: str
) -> str:
scores = dict()
for candidate in possible_matches:
n = len(candidate.split())
n_grams = generate_ngrams(string_to_be_searched, n)
@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 / 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 / SQL
Last active September 9, 2022 10:07
INTEGER
BOOLEAN
TEXT
FLOAT
DOUBLE
CHARACTER(num_chars)
VARCHAR(num_chars)
DATE
DATETIME
BLOB
"""
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):