Skip to content

Instantly share code, notes, and snippets.

StSav012 /
Last active October 4, 2022 07:47
Find the longest common sequences of two sequences given
from typing import Iterable, Iterator, Sequence, TypeVar
_T = TypeVar('_T')
def arg_max(x: Iterable[_T]) -> int | None:
""" find the index of the largest item in the series """
am: int | None = None
max_x: _T | None = None
for i, x_i in enumerate(x):
# -*- coding: utf-8 -*-
from typing import List, Dict
import urllib.request
import urllib.error
import os.path
FILES: List[str] = [
# 'test',
# 'aes_light',
StSav012 / parser.c
Last active February 27, 2018 06:34
INI file parser
View parser.c
#include <stdlib.h>
#include <stdio.h>
* @function readValue extracts a string value from an INI file
* @param f is a file opened for reading outside the function
* @param section is the section name to look into
* @param key is the key which value is required
* @param buffer is a buffer to store the key value into
* @note @param buffer should be long enough to store the value
StSav012 / calendar.tex
Last active December 7, 2017 17:15
Calendar Generator
View calendar.tex
\hypersetup{pdftex, pdftitle=Calendar, pdfauthor=StSav012}
StSav012 / sliders.html
Last active October 31, 2017 15:21
An example of a dynamically created table of sliders, and their values, and miscellaneous info
View sliders.html
<!DOCTYPE html>
<meta charset="utf-8">
* {
color: inherit;
background: inherit;
StSav012 /
Last active October 30, 2017 17:38
rp5 site parser
place="Нижний Новгород"
file=$(curl -s -o - "${lang}&q=${place}")
links=$(echo ${file} | grep -o -e "p class=\"navy\">.*<form id=\"f\"" | grep -o -e "=[^=]*" | tail -n +2 | head -n -1)
code=$(echo ${links} | grep -Eo -e "\"[[:digit:]]+" | grep -Eo -e "[[:digit:]]+" | head -n 1)
name=$(echo ${links} | grep -Eo -e "${lang}\">[^<]+" | grep -Eo -e ">.+" | grep -Eo -e "[^>]+" | head -n 1)
file=$(wget -q -O - "${code}/${lang}")
StSav012 / rk4_mpi.c
Created November 29, 2016 12:58
RK4 w/ MPI
View rk4_mpi.c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <mpi.h>
#define formaster if(id==0)
#define forothers if(id!=0)
#define dim 2
#define USE_DEFAULT 1 // skip user input
#define DO_HARLEM_SHAKE 1 // show the result
StSav012 / rk4_omp.cpp
Last active November 29, 2016 12:59
RK4 w/ OMP
View rk4_omp.cpp
#include <cstdlib>
#include <iostream>
#include <vector>
#include <ctime>
#include <omp.h>
using namespace std;
#define dim 2
#define USE_DEFAULT 1 // skip user input