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 <stdlib.h> | |
#include <string.h> | |
#include <Windows.h> | |
typedef struct { | |
void (*handler)(char *); | |
char parameter[128]; | |
int interval, last_emitted; | |
} Event; |
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 <conio.h> | |
#include <Windows.h> | |
#define MAX_BULLETS_COUNT 100 | |
typedef struct { | |
int alive; | |
char ch; | |
int x, y, color; |
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 datetime import date | |
def is_leap_year(year): | |
try: date(year, 2, 29) | |
except ValueError: return False | |
else: return True |
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
f=lambda a,b,n:f(b,a+b,n-1)if n>1else b # simple and fast | |
# for test | |
import sys | |
sys.setrecursionlimit(5001) # as default, it was 1000 in my computer | |
print(f(0,1,5000)) # 0 1 1 2 3 5 8 13 21 ... | |
print(f(1,1,5000)) # 1 1 2 3 5 8 13 21 34 ... |
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 pygame | |
from pygame.locals import * | |
WIDTH, HEIGHT = 100, 100 | |
PIXEL_SIZE = 5 # should be bigger than 1 | |
SCREEN_WIDTH, SCREEN_HEIGHT = WIDTH * PIXEL_SIZE, HEIGHT * PIXEL_SIZE | |
surf = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT)) | |
surf.fill((0, 0, 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
class SliceTime(object): | |
@property | |
def hour(self): | |
return self._hour | |
@hour.setter | |
def hour(self, value): | |
if not isinstance(value, (int, long)) or not 0 <= value <= 23: | |
raise ValueError('hour must be an integer value in 0 ~ 23') | |
else: |
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
# coding: utf-8 | |
import requests | |
import time | |
from urlparse import parse_qsl | |
from bs4 import BeautifulSoup | |
class KakaostoryAPI(object): | |
def __init__(self, raw_cookie): | |
self.session = requests.Session() |
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
# coding: utf-8 | |
import requests | |
import time | |
class KakaoStoryAPI(object): | |
def __init__(self, cookie): | |
self.headers = { | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) Gecko/20100101 Firefox/37.0', | |
'Accept': 'application/json', |
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
try: | |
import cPickle as pickle | |
except ImportError: | |
import pickle | |
import zlib | |
from Crypto.Cipher import AES | |
from Crypto.Hash import MD5 | |
from Crypto import Random | |
from base64 import b64encode, b64decode |
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 re | |
import inspect | |
FORMAT_REGEX = re.compile(r'\\\(([a-zA-Z_]\w*)\)') | |
def formatted(string, silent=False): | |
to_be_replaced = FORMAT_REGEX.findall(string) | |
variables = inspect.stack()[1][0].f_locals | |
for item in to_be_replaced: | |
if item in variables: | |
string = string.replace('\({})'.format(item), str(variables[item])) |