Skip to content

Instantly share code, notes, and snippets.

View ashtanyuk's full-sized avatar

Anton A. Shtanyuk ashtanyuk

View GitHub Profile
@ashtanyuk
ashtanyuk / TextFreq.py
Created January 18, 2023 14:10
Частотный анализ слов на примере "Войны и мира"
import itertools
import matplotlib.pyplot as plt
import numpy as np
with open("war_peace.txt", "r") as file:
content = file.readlines();
print("Всего строк", len(content))
notEmpty = list(filter(lambda s: len(s) > 1, content))
print("Непустых строк", len(notEmpty))
@ashtanyuk
ashtanyuk / connect.java
Created January 15, 2023 17:34
Connect to sqlite
public boolean connect(String workDir, String dbname) {
try {
Class.forName("org.sqlite.JDBC");
String url = "jdbc:sqlite:/" + workDir + "/" + dbname + ".db";
conn = DriverManager.getConnection(url);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
@ashtanyuk
ashtanyuk / LessonInfo.java
Last active January 16, 2023 10:35
ListFactory for ListView java
public class LessonInfo {
public LocalDate date;
public String pair;
public String lessonType;
public LessonInfo(LocalDate date, String pair, String lessonType) {
this.date = date;
this.pair = pair;
this.lessonType = lessonType;
}
@ashtanyuk
ashtanyuk / DayOfWeek.java
Last active January 15, 2023 17:31
get weekday from LocalDate (russian)
date.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.getDefault())
@ashtanyuk
ashtanyuk / DateTimeFormatter.java
Created January 15, 2023 17:01
Convert LocalDate to String
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return date.format(formatter);
@ashtanyuk
ashtanyuk / ann-2.ipynb
Created May 11, 2022 12:33
ANN-2.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ashtanyuk
ashtanyuk / uniqStrings.sh
Last active January 19, 2023 09:14
Отбор уникальных строк из файла
#!/bin/bash
awk '!seen[$0]++' class.txt > class-1.txt
@ashtanyuk
ashtanyuk / isNewObj.cpp
Created March 5, 2022 17:16
Проверка объектов в коллекции
// true - если объект ранее не встречался среди ближайших
// false - если он был ранее найден (по id)
// поиск ведем в векторе результатов
bool isNewObj1(std::vector<ScaleObjInfo>& result, ScaleObjInfo* minSOI) {
for (auto& t : result) {
if (t.pobj->id == minSOI->pobj->id)
return false;
}
return true;
}
@ashtanyuk
ashtanyuk / closest.h
Last active October 17, 2021 20:08
Find the closest item in tree (std::set)
template<typename Set>
auto closest_element(Set& set, const typename Set::value_type& value)
-> decltype(set.begin())
{
const auto it = set.lower_bound(value);
if (it == set.begin())
return it;
const auto prev_it = std::prev(it);
return (it == set.end() || value - *prev_it <= *it - value) ? prev_it : it;
@ashtanyuk
ashtanyuk / serp.py
Created October 11, 2021 20:18
Serpinsky Triangle
def serp(n):
d = ['*']
for i in range(n):
sp = " "*(2**i)
d = [sp+x+sp for x in d] + [x+" "+x for x in d]
return d
print ("\n".join(serp(4)))