This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
from socket import AF_INET, SOCK_DGRAM | |
import socket | |
PORT = 9091 | |
sock = socket.socket(AF_INET, SOCK_DGRAM) | |
# assign socket to host (empty for any) and port (as tuple, not as two params!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pluralizeRussian(number, nom_sing, gen_sing, gen_pl): | |
s_last_digit = str(number)[-1] | |
if int(str(number)[-2:]) in range(11,20): | |
#11-19 | |
return gen_pl | |
elif s_last_digit == '1': | |
#1 | |
return nom_sing | |
elif int(s_last_digit) in range(2,5): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import functools | |
def timer(func): | |
#Decorator function takes the decorated function as parameter | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
#the replacement function to be used |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 -u | |
# -*- coding: utf-8 -*- | |
import sys, traceback | |
def full_traceback(): | |
""" | |
Returns a full traceback to an exception | |
:return: | |
""" | |
exc_type, exc_value, exc_traceback = sys.exc_info() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
parser = argparse.ArgumentParser() | |
# add a positional argument. THey are treated as strings by default | |
parser.add_argument("echo", help="echo the string you use here") | |
# tell it to treat the argument as an integer | |
parser.add_argument("square", help="display a square of a given number", | |
type=int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
a = np.array([20, 30, 40, 50]) | |
b = np.arange(4) | |
# mathematical operationscan be done with arrays. Arrays should be of same size and dimensions | |
print(a+b) # [20 31 42 53] | |
print(a-b) # [20 29 38 47] | |
print(a*b) # [0 30 80 150] | |
print(a/b) # [inf 30 20 16.6666667] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.reddit.com/r/dailyprogrammer/comments/4m3ddb/20160601_challenge_269_intermediate_mirror/ | |
import numpy as np | |
def decrypt(inp): | |
mirrors = np.array(list(map(list ,MIRRORS.split('\n')))) | |
TOP = [chr(i) for i in range(97,110)] | |
RIGHT = [chr(i) for i in range(110,123)] | |
LEFT = [chr(i) for i in range(65,78)] | |
BOTTOM = [chr(i) for i in range(78,91)] | |
result = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char const *argv[]) | |
{ | |
int ndigits[10] = {0}; | |
memset(ndigits, 0, 10 * sizeof(int));//init with zeroes | |
int n_spaces = 0; | |
int n_others = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INPUT = "terminator" | |
REPLACERS = { | |
"o" : {"0", "Q"}, | |
"i" : {"1",}, | |
"a" : {"@",}, | |
"e" : {"3",}, | |
} | |
# Add capitals |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | |
def msg_process(bot, update): | |
bot.sendMessage(131711493,update.message.text + " hello") | |
updater = Updater("176032236:AAF6h2YjwtUfsLP5K5O5wD8xV2dg3VadL5k") | |
disp = updater.dispatcher | |
updater.start_webhook(listen='0.0.0.0', |
OlderNewer