Skip to content

Instantly share code, notes, and snippets.

View kupp1's full-sized avatar
🎓
ITMO

Dmitrii Kupershtein kupp1

🎓
ITMO
View GitHub Profile
@kupp1
kupp1 / ircparse.coffee
Last active August 15, 2018 18:32
A regular expression that parses RFC2812 (IRC protocol)
# original work by Michael F. Lamb. License: GPLv3.
# added optional tilde before !user by kupp
RFC2812Matcher = ///
^ # We'll match the whole line. Start.
# Optional prefix and the space that separates it
# from the next thing. Prefix can be a servername,
# or nick[[!user]@host]
(?::( # This whole set is optional but if it's
# here it begins with : and ends with space
@kupp1
kupp1 / irc.coffee
Last active August 16, 2018 06:43
coffeescript irc (telnet) sample
net = require 'net'
host = 'irc.run.net'
port = 6660
pingRegExp = RegExp("^PING : #{host}\r\n$")
sendMsg = (socket, data) ->
socket.write(data + '\r\n')
matchPing = (data) ->
@kupp1
kupp1 / boll.cpp
Last active August 27, 2018 07:16
SFML C++ SAMPLE
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp>
bool chkFunc(sf::Vector2i pos, sf::Vector2f pos_c) {
if ( sf::Mouse::isButtonPressed(sf::Mouse::Left) && pos.x >= pos_c.x && pos.x <= pos_c.x+100 && pos.y >= pos_c.y && pos.y <= pos_c.y+100 ) {
std::cout << "ya1" << "\n";
return true;
} else {
@kupp1
kupp1 / task121.c
Created August 30, 2018 09:05
UniLecs #121. cAPS LOCK
#include <stdio.h>
int main (int argc, char* argv[]) {
if (argc < 2) {
return -1, printf("missing argument\n");
}
for (int i = 1; i < argc; i++) {
while (*argv[i] != '\0') {
if (*argv[i] >= 65 && *argv[i] <= 90)
putchar(*argv[i] + 32);
@kupp1
kupp1 / erato.py
Last active August 31, 2018 06:27
Sieve of Eratosthenes
"""
Sieve of Eratosthenes
"""
import math
def erato_bool(n: int):
"""
Returned list of primary numbers form 2 to n-1
"""
if n <= 2:
@kupp1
kupp1 / kadane.py
Created September 1, 2018 19:15
UniLecs #122. max submatrix sum
# def check_rectangle_matrix(matrix: list):
# """
# Check if matrix is rectangle list matrix
# """
# if matrix and isinstance(matrix, list):
# x_len = len(matrix[0])
# for array in matrix:
# if len(array) != x_len or not isinstance(array, list):
# return False
# return True
@kupp1
kupp1 / uniqueSym.c
Created September 2, 2018 12:05
UniLecs #1. Unique symbols
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool checkUniqueSymbols(char* string) {
for (int i = 0; i < strlen(string); i++) {
for (int j = i + 1; j < strlen(string); j++) {
if (string[i] == string[j]) {
return false;
}
@kupp1
kupp1 / shift.py
Created September 3, 2018 16:41
Circular array shift
def reverse_array(array: list, start, stop):
tmp = array[start:stop]
array[start:stop] = reversed(tmp)
return array
def circular_array_shift(array: list, shift: int):
if array and shift:
length = len(array)
shift %= length
array = reverse_array(array, 0, length)
@kupp1
kupp1 / disc.txt
Last active September 18, 2018 17:39
UniLecs #127. Интервальная сумма
Задача: даны два натуральных числа a, b. Необходимо найти сумму чисел на интервале [a, b] (включая концы интервала).
Входные данные: a, b, где a <= b. a, b от 1 до 10^9.
Вывод: sum - сумма чисел на интервале [a, b].
Пример: a = 1, b = 3
@kupp1
kupp1 / disc.txt
Created September 26, 2018 14:04
UniLecs #122 Битовая Арифметика
Задача: даны два числа K, N. Необходимо вычислить арифметическое выражение вида:
K * 2^N, используя только битовые операции.
Входные данные: K, N - натуральные числа, где K от 1 до 10^3, N от 1 до 20
Вывод: результат выражения K * 2^N
Пример: K = 3, N = 4