Skip to content

Instantly share code, notes, and snippets.

from django.core.signing import TimestampSigner
TimestampSigner(key="arbitrary key",salt="arbitrary character").sign("hello")
# 'hello:1nupuX:K_GIN7mgJdcqxshVqZlqoNPG7jY3whN-oo7RALBuS_E'
TimestampSigner(key="arbitrary key",salt="arbitrary character").unsign('hello:1nupuX:K_GIN7mgJdcqxshVqZlqoNPG7jY3whN-oo7RALBuS_E')
# 'hello'
from django.utils.crypto import salted_hmac
salted_hmac('arbitrary salt', 'hello', secret="arbitrary secret key", algorithm="md5").digest()
from django.core import signing
signing.dumps('Hello World')
# 'IkhlbGxvIFdvcmxkIg:1nuq1R:XGmDLtvO1Ru77QX7trHD5bCzRsaxTQVKTx9Jxv4Wj6A'
signing.loads('IkhlbGxvIFdvcmxkIg:1nuq1R:XGmDLtvO1Ru77QX7trHD5bCzRsaxTQVKTx9Jxv4Wj6A')
# 'Hello World'
@rainyman2012
rainyman2012 / decorator.py
Created April 10, 2022 08:56
decorator in python
def sensitive_post_parameters(*parameters):
"""
Indicate which POST parameters used in the decorated view are sensitive,
so that those parameters can later be treated in a special way, for example
by hiding them when logging unhandled exceptions.
Accept two forms:
* with specified parameters:
import numpy as np
day_price = np.array([[0,7], [1,12], [2,5], [3,3], [4,11], [5, 6], [6,10] ,[7,2], [8,0]])
results = np.zeros((9, 9))
print(results)
for buy in day_price:
for sell in day_price:
if buy[0] < sell[0]:
import threading
import time
def blocking_1():
print("thread start 1")
time.sleep(10)
print("thread finished 1")
def blocking_2():
print("thread start 2")
import threading
import time
def blocking_io():
print("thread start")
time.sleep(10)
print("thread finished")
def main():
t1 = threading.Thread(target=blocking_io, name="blocking_task")
import threading
import time
def blocking_io():
print("thread start")
time.sleep(10)
print("thread finished")
def main():
t1 = threading.Thread(target=blocking_io, name="blocking_task")
#!/bin/bash
REQUIREMENTS="""
Django\n
daphne\n
"""
PROJECT_NAME=$1
if [ -z $PROJECT_NAME ]
then
PROJECT_NAME=test_$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1)
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs: