Skip to content

Instantly share code, notes, and snippets.

View SpeedSX's full-sized avatar

speedsx SpeedSX

  • Kyiv, Ukraine
View GitHub Profile
#include <QApplication>
#include <QMainWindow>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QString>
#include <QScrollBar>
#include <windows.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <CommCtrl.h>
#pragma comment(lib, "Comctl32.lib")
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
#include <windows.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
// Window procedure declaration
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Global variables
@SpeedSX
SpeedSX / rounded_corners.py
Last active March 5, 2024 12:12
Draws a smooth closed curve that goes outside of all the given points and not closer than distance D
from shapely.geometry import LineString
import matplotlib.pyplot as plt
# Given points
points = [(5, 0), (10, 20), (20, 20), (20, 30), (30, 30), (30, 10), (5, 0)]
# Distance threshold
D = 5
line = LineString(points)
@SpeedSX
SpeedSX / IterMut.rs
Created May 13, 2021 05:28
Multiole mutable refs to array elements
use itertools::Itertools;
use std::slice::IterMut;
fn foo(s0: &mut String, s1: &mut String, s2: &mut String) {
s0.push_str("!");
s1.push_str("!!");
s2.push_str("!!!");
}
struct MutIterator<'a, T> {
@SpeedSX
SpeedSX / is_valid_hack.rs
Created January 28, 2021 13:32
Valid Parenthesis task implementation. Even faster method but using direct compare instead of hash table or array, so I don't consider it as a good solution.
pub fn is_valid_hack(s: &str) -> bool {
if s.len() % 2 == 1 {
return false;
}
let mut par: Vec<char> = Vec::new();
for c in s.chars() {
let i =
@SpeedSX
SpeedSX / is_valid_fastest.rs
Created January 28, 2021 12:15
Valid Parenthesis task implementation. Fastest solution found, though it uses string slice instead of String and pre-allocates character buffer.
pub fn is_valid(s: &str) -> bool {
if s.len() % 2 == 1 {
return false;
}
let closing = vec![')', ']', '}'];
let opening = vec!['(', '[', '{'];
let mut par: Vec<char> = Vec::with_capacity(s.len());
@SpeedSX
SpeedSX / is_valid_with_hash.rs
Created January 28, 2021 11:30
Valid parentheses task. Implementation with HashMap
pub fn is_valid(s: String) -> bool {
if s.len() % 2 == 1 {
return false;
}
let mut brackets = HashMap::new();
brackets.insert(')', '(');
brackets.insert(']', '[');
brackets.insert('}', '{');
fn bottles(n: u32) -> String {
if n > 1 {
format!("{} bottles", n)
} else if n == 1 {
"1 bottle".to_string()
} else {
"no more bottles".to_string()
}
}
@SpeedSX
SpeedSX / RWLock.cs
Created December 25, 2020 20:32
ReaderWriteerLockSlim wrapper
class RWLock : IDisposable
{
public struct WriteLockToken : IDisposable
{
private readonly ReaderWriterLockSlim @lock;
public WriteLockToken(ReaderWriterLockSlim @lock)
{
this.@lock = @lock;
@lock.EnterWriteLock();
}