Skip to content

Instantly share code, notes, and snippets.

@selimslab
selimslab / sensor.c
Last active August 7, 2019 20:15
TSL-2561 light sensor library for Nordic nRF 51822
#include < stdio.h >
#include "boards.h"
#include "app_util_platform.h"
#include "app_uart.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"
#include "main.h"
/* Define version of GCC. */
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)
from collections import defaultdict
class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
<style>
:root{
--main: hsl(230, 44%, 55%);
--secondary: hsl(230, 44%, 55%)
}
body{
background-color: var(--main)
}
html{
func climbStairs(n int) int {
memo := map[int]int{
1:1,
2:2,
}
var climb func(n int) int
climb = func (n int) int {
_, ok := memo[n];
if !ok {
@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:
@selimslab
selimslab / SQL
Last active September 9, 2022 10:07
INTEGER
BOOLEAN
TEXT
FLOAT
DOUBLE
CHARACTER(num_chars)
VARCHAR(num_chars)
DATE
DATETIME
BLOB
@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
@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 / 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;