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 / ipstack.py
Created July 1, 2018 11:51
ipstack api usage on python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#ipstack replace freegeoip :"((
import urllib.request
import json
token = '' #get token on ipstack.com
@kupp1
kupp1 / atoi.c
Last active July 11, 2018 08:01
c lang atoi
#include "atoi.h"
int main (int argc, char* argv[]) {
printf("%d\n", atoi(argv[1]));
return 0;
}
@kupp1
kupp1 / calc.py
Created July 11, 2018 16:05
Python3 string calculator
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from calc_parser import calc_parser
def evaluate(expression: list):
for i in range(len(expression)):
if expression[i] != '+' and expression[i] != '-' and expression[i] != '*' and expression[i] != '/':
if '.' in expression[i]:
@kupp1
kupp1 / url-resolve.py
Last active August 21, 2018 11:18
python3 url resolver
import re
from bs4 import BeautifulSoup
from bs4 import SoupStrainer
import urllib.request
import ssl
import urllib.parse
import urllib.error
from PIL import Image
@kupp1
kupp1 / Pifagor_table.c
Last active August 2, 2018 16:00
Pifagor table
#include <stdio.h>
void main() {
int i;
int j;
for (i = 1; i < 10; i++) {
for (j = 1; j < 10; j++)
printf("%2d ", i*j);
putchar('\n');
}
@kupp1
kupp1 / multiplication_table_in_one_line.py
Last active July 30, 2018 06:48
Multiplication table
(lambda x: [[print('%d X %d = %2d' % (j, i, i*j), end='\t' if j < x else '\n') for j in range(1, x+1)] for i in range(1, x + 1)])(9)
# Output:
# 1 X 1 = 1 2 X 1 = 2 3 X 1 = 3 4 X 1 = 4 5 X 1 = 5 6 X 1 = 6 7 X 1 = 7 8 X 1 = 8 9 X 1 = 9
# 1 X 2 = 2 2 X 2 = 4 3 X 2 = 6 4 X 2 = 8 5 X 2 = 10 6 X 2 = 12 7 X 2 = 14 8 X 2 = 16 9 X 2 = 18
# 1 X 3 = 3 2 X 3 = 6 3 X 3 = 9 4 X 3 = 12 5 X 3 = 15 6 X 3 = 18 7 X 3 = 21 8 X 3 = 24 9 X 3 = 27
# 1 X 4 = 4 2 X 4 = 8 3 X 4 = 12 4 X 4 = 16 5 X 4 = 20 6 X 4 = 24 7 X 4 = 28 8 X 4 = 32 9 X 4 = 36
# 1 X 5 = 5 2 X 5 = 10 3 X 5 = 15 4 X 5 = 20 5 X 5 = 25 6 X 5 = 30 7 X 5 = 35 8 X 5 = 40 9 X 5 = 45
# 1 X 6 = 6 2 X 6 = 12 3 X 6 = 18 4 X 6 = 24 5 X 6 = 30 6 X 6 = 36 7 X 6 = 42 8 X 6 = 48 9 X 6 = 54
# 1 X 7 = 7 2 X 7 = 14 3 X 7 = 21 4 X 7 = 28 5 X 7 = 35 6 X 7 = 42 7 X 7 = 49 8 X 7 = 56 9 X 7 = 63
# 1 X 8 = 8 2 X 8 = 16 3 X 8 = 24 4 X 8 = 32 5 X 8 = 40 6 X 8 = 48 7 X 8 = 56 8 X 8 = 64 9 X 8 = 72
@kupp1
kupp1 / addition_table_in_one_line.py
Last active July 31, 2018 09:17
Addition table
(lambda x, max_len: [[print('%{}d'.format(max_len) % (i + j) if i + j != 0 else ' ' * max_len, end=' ' if j < x else '\n') for j in range(0, x + 1)] for i in range(0, x + 1)])(9, 2)
# Output:
# 1 2 3 4 5 6 7 8 9
# 1 2 3 4 5 6 7 8 9 10
# 2 3 4 5 6 7 8 9 10 11
# 3 4 5 6 7 8 9 10 11 12
# 4 5 6 7 8 9 10 11 12 13
# 5 6 7 8 9 10 11 12 13 14
# 6 7 8 9 10 11 12 13 14 15
# 7 8 9 10 11 12 13 14 15 16
#!/bin/bash
#Install sl package and enjoy!
while :
do
sl
done
@kupp1
kupp1 / sorts_n2.hpp
Last active September 26, 2018 16:36
Sort Methods
#include <vector>
template <class T>
void bubble_sort(std::vector<T> &vec) {
//Bubble Sort
T tmp;
for (unsigned int i = 0; i < vec.size(); i++) {
for (unsigned int j = 0; j < vec.size()-1; j++) {
if (vec[j] > vec[j+1]) {
tmp = vec[j];
@kupp1
kupp1 / gauss.py
Created August 7, 2018 12:07
Gauss circle problem
# brute-force solution 1
radius = float(input('Enter radius: '))
square_radius = radius * radius
int_count = 0
max_int = int(radius)
min_int = (-1) * max_int
for i in range(min_int, max_int + 1):
for j in range(min_int, max_int + 1):
if (i*i) + (j*j) <= square_radius:
int_count += 1