This file contains 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
# create table topics! | |
create table topics ( | |
id int primary key auto_increment, | |
name varchar(256), | |
parent_id int null, | |
type smallint not null, | |
foreign key (parent_id) references topics(id), | |
index(type) | |
); |
This file contains 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 bisect | |
import random | |
import time | |
from datetime import datetime | |
def get_locations_1(x, arr): | |
return [bisect.bisect_left(l, x) for l in arr] | |
def get_pos_arr(arr): | |
# For each of the element in `arr` positions will hold |
This file contains 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
$ SHOW ENGINE INNODB STATUS | |
---------------------- | |
BUFFER POOL AND MEMORY | |
---------------------- | |
Total memory allocated 137363456; in additional pool allocated 0 | |
Dictionary memory allocated 159646 | |
Buffer pool size 8191 | |
Free buffers 7741 | |
Database pages 449 | |
Old database pages 0 |
This file contains 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 get_page(page_id:int) -> Page: | |
# Check if the page is available in the cache | |
page = cache.get_page(page_id) | |
# if the page is retrieved from the main memory | |
# return the page. | |
if page: | |
return page | |
This file contains 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 is_allowed(key:str) -> Bool: | |
"""The function decides is the current request should be served or not. | |
It accepts the configuration key `key` and checks the number of requests made against it | |
as per the configuration. | |
The function returns True if the request goes through and False otherwise. | |
""" | |
current_time = int(time.time()) | |
# Fetch the configuration for the given key | |
# the configuration holds the number of requests allowed in a time window. |
This file contains 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 register_request(key, ts): | |
store[key][ts] += 1 |
This file contains 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 get_current_window(key, start_time): | |
ts_data = requests_store.get(key) | |
if not key: | |
return 0 | |
total_requests = 0 | |
for ts, count in ts_data.items(): | |
if ts > start_time: | |
total_requests += count | |
else: |
This file contains 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 get_ratelimit_config(key): | |
value = cache.get(key) | |
if not value: | |
value = config_store.get(key) | |
cache.put(key, value) | |
return value |
This file contains 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
export PYTHONSTARTUP="$HOME/ipython.py" |
This file contains 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 sys | |
class IPythonPromptPS1(object): | |
def __init__(self): | |
self.line = 0 | |
def __str__(self): | |
self.line += 1 | |
return "\033[92mIn [%d]:\033[0m " % (self.line) | |
sys.ps1 = IPythonPromptPS1() | |
sys.ps2 = " \033[91m...\033[0m " |
NewerOlder