Skip to content

Instantly share code, notes, and snippets.

View FloydanTheBeast's full-sized avatar
⚙️
Grinding

Shadi Abdelsalam FloydanTheBeast

⚙️
Grinding
View GitHub Profile
from nltk import sent_tokenize, word_tokenize
from string import punctuation
from collections import defaultdict
import operator
def count_one_symbol_words(word_list):
counter = 0
for word in word_list:
if len(word) == 1 and word not in punctuation:
counter += 1
@FloydanTheBeast
FloydanTheBeast / IntegerInput.cs
Created November 4, 2019 11:03
Integer input with predicate as a parameter
/// <summary>
/// Метод для ввода целочисленного значения
/// </summary>
/// <param name="isCorrect">Предикат, проверяющий правильность ввода</param>
/// <returns>Введённое из консоли число</returns>
public static int IntInput(Func<int, bool> isCorrect = null, string msg = null)
{
if (msg != null)
{
Console.WriteLine(msg);
@FloydanTheBeast
FloydanTheBeast / Logger.cs
Created November 4, 2019 11:05
Logger into file
static readonly string loggerPath = Path.Combine(Environment.CurrentDirectory, "Log.txt");
public static void Logger(string log)
{
try
{
File.AppendAllText(loggerPath, log + "\n");
}
catch (IOException ex)
{
@FloydanTheBeast
FloydanTheBeast / stylesheets.py
Created January 12, 2020 15:38
PyQt stylesheets example
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QVBoxLayout
app = QApplication([])
window = QWidget()
# Применение стилей напрямую к элементу
window.setStyleSheet('background-color: #0E171E')
layout = QVBoxLayout()
@FloydanTheBeast
FloydanTheBeast / signals-and-slots.py
Last active January 12, 2020 16:48
PyQt signals and slots example.py
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSlider, QProgressBar
from PyQt5.QtCore import Qt
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
slider = QSlider(Qt.Horizontal)
progressBar = QProgressBar()
@FloydanTheBeast
FloydanTheBeast / custom-slot.py
Created January 12, 2020 17:45
PyQt custom slot example
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QScrollBar, QMessageBox
from PyQt5.QtCore import Qt
class Example(QWidget):
def __init__(self):
super(QWidget, self).__init__()
self.scrollBar = QScrollBar(Qt.Horizontal)
self.scrollBar.valueChanged.connect(self.customSlot)
@FloydanTheBeast
FloydanTheBeast / custom-signals.py
Last active January 12, 2020 23:13
Custom signal example
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSlider, QLabel
from PyQt5.QtCore import Qt, pyqtSignal
class ColorPicker(QWidget):
scrollChanged = pyqtSignal(tuple, name='ScrollChanged')
color = { 'r': 0, 'g': 0, 'b': 0 }
def __init__(self):
super().__init__()
@FloydanTheBeast
FloydanTheBeast / event-handler-override.py
Created January 12, 2020 23:35
Event handler override example
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox, QLabel, QVBoxLayout
from PyQt5.QtCore import Qt
class UI(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout()
self.label = QLabel('x: _; y: _')
self.label.setStyleSheet('font-size: 48px; font-weight: 800')
@FloydanTheBeast
FloydanTheBeast / volcanoes.csv
Created January 13, 2020 09:43
Volcanoes in the USA dataset
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 10 columns, instead of 5. in line 8.
VOLCANX020,NUMBER,NAME,LOCATION,STATUS,ELEV,TYPE,TIMEFRAME,LAT,LON
509.000000000000000,1201-01=,Baker,US-Washington,Historical,3285.000000000000000,Stratovolcanoes,D3,48.7767982,-121.8109970
511.000000000000000,1201-02-,Glacier Peak,US-Washington,Tephrochronology,3213.000000000000000,Stratovolcano,D4,48.1118011,-121.1110001
513.000000000000000,1201-03-,Rainier,US-Washington,Dendrochronology,4392.000000000000000,Stratovolcano,D3,46.8698006,-121.7509995
515.000000000000000,1201-05-,St. Helens,US-Washington,Historical,2549.000000000000000,Stratovolcano,D1,46.1997986,-122.1809998
516.000000000000000,1201-04-,Adams,US-Washington,Tephrochronology,3742.000000000000000,Stratovolcano,D6,46.2057991,-121.4909973
517.000000000000000,1201-06-,West Crater,US-Washington,Radiocarbon,1329.000000000000000,Volcanic field,D7,45.8797989,-122.0810013
518.000000000000000,1201-07-,Indian Heaven,US-Washington,Radiocarbon,1806.000000000000000,Shield volcanoes,D7,45.9297981,-121.8209991
519.000000000000000,1202-01-,Hood,US-Oregon,Histo
@FloydanTheBeast
FloydanTheBeast / Cpp unsync streams and untie cin.md
Last active May 23, 2020 19:43
Cpp unsync streams and untie cin

This code optimizes prefomance as a side effect. USE CAREFULY

The two calls have different meanings that have nothing to do with performance; the fact that it speeds up the execution time is (or might be) just a side effect. You should understand what each of them does and not blindly include them in every program because they look like an optimization.

ios_base::sync_with_stdio(false);

This disables the synchronization between the C and C++ standard streams. By default, all standard streams are synchronized, which in practice allows you to mix C- and C++-style I/O and get sensible and expected results. If you disable the synchronization, then C++ streams are allowed to have their own independent buffers, which makes mixing C- and C++-style I/O an adventure.

Also keep in mind that synchronized C++ streams are thread-safe (output from different threads may interleave, but you get no data races).