Skip to content

Instantly share code, notes, and snippets.

View smertelny's full-sized avatar

Serhii Smertelnyi smertelny

View GitHub Profile
@smertelny
smertelny / merge_sort.rs
Last active February 3, 2020 09:36
Rust merge sort
#[inline]
fn merge<T>(left: &mut [T], right: &mut [T]) -> Vec<T>
where T: PartialOrd + Copy + Default
{
let mut array:Vec<T> = vec![T::default(); left.len() + right.len()];
let (mut left_idx, mut right_idx, mut idx) = (0, 0, 0);
while left_idx < left.len() && right_idx < right.len() {
if left[left_idx] != left[left_idx] {
array[idx] = right[right_idx];
@smertelny
smertelny / merge_sort.py
Created January 24, 2020 21:27
algorithms: merge sort
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import List
def merge_sort(array: List[int]):
if len(array) <= 1:
return
mid = len(array) // 2
@smertelny
smertelny / chapter-13.rs
Created October 27, 2019 06:35
Rust book Chapter 13. Casher with HashMap
use std::collections::HashMap;
use std::thread;
use std::time::Duration;
struct Casher<T, K, V>
where
T: Fn(K) -> V,
{
calculation: T,
value: HashMap<K, V>,
@smertelny
smertelny / exercise8-3-1.rs
Last active October 17, 2019 19:05
My answer to Exercise from 8th part of RustBook Rust lang
use std::collections::HashMap;
fn main() {
let integer_list = [
20, 47, 85, 99, 80, 86, 90, 89, 74, 9, 51, 78, 86, 36, 4, 68, 71, 42, 1, 64,
];
let mut result_vec: Vec<f64> = vec![0.0; 3];
result_vec[0] = integer_list.iter().sum::<i64>() as f64 / integer_list.iter().count() as f64;
{
@smertelny
smertelny / exercise3-3.c
Last active July 9, 2019 19:59
Exercise 3-3 from K&R The C programming language Book
/** Exercise 3-3 from K&R The C programming language Book */
#include <stdio.h>
#include <ctype.h>
#define MAX_LENGTH 1000
void expand(char s1[], char s2[]);
int main()
@smertelny
smertelny / index.j2
Last active September 25, 2018 20:40
Just testet aiohttp server with subscription with RethinkDB
<html>
<head></head>
<body>
<h1>Hello World</h1>
<ul id="test">
</ul>
<input type='text' id="input_node"/>
<button onClick="send_data()">Send data!</button>
<script src="{{ static('index.js') }}"></script>
</body>
#!/usr/bin/env python3
from random import randint
counter = {
'wins': 0,
'games': 0
}
print('Hello! I wanna play a little game')