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 functools import wraps | |
import trio | |
def set_result(results, key, func): | |
@wraps(func) | |
async def wrapper(*args, **kwargs): | |
results[key] = await func(*args, **kwargs) |
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 django.db import connection | |
DB_NAME = "your-db-name" | |
cursor = connection.cursor() | |
tables = connection.introspection.table_names() | |
cursor.execute(f"ALTER DATABASE `{DB_NAME}` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci") | |
for table in tables: | |
cursor.execute(f"ALTER TABLE {table} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci") |
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 zbar | |
import cv2 | |
from PIL import Image | |
def scan_barcodes(img): | |
""" | |
Scan barcodes in image and return their data. | |
:param img: Source image | |
:type img: PIL.Image |
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 decimal import Decimal | |
def percentage_change(old_value, new_value): | |
""" | |
Accepts two integers, an old and a new number, | |
and then measures the percent change between them. | |
""" | |
change = abs(new_value - old_value) | |
try: | |
pct_change = (change / Decimal(old_value)) |
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
# Install jessie-backports APT repository and OpenSSL 1.0.2: | |
echo "deb http://ftp.debian.org/debian jessie-backports main" | sudo tee /etc/apt/sources.list.d/jessie-backports.list | |
gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553 | |
gpg -a --export 8B48AD6246925553 | sudo apt-key add - | |
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010 | |
gpg -a --export 7638D0442B90D010 | sudo apt-key add - | |
sudo apt-get update | |
sudo apt-get -yt jessie-backports install libssl-dev openssl |
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
#!/bin/sh | |
# ejp/imagination/20.12.2012: install-eth-drivers.sh | |
# Build the ethernet drivers for Atheros AR8161, | |
# install them, bring the interface up and get | |
# an IP address. | |
set -e | |
# Get the password before the user gets a cup of tea |
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
#!/bin/bash | |
cd /var/log/apache2 | |
i=`date +%d/%b/%Y` | |
j=`cat other_vhosts_access.log | grep “$i” | grep "GET / HTTP/1." | wc -l` | |
echo "No. of Apache Access Count:$j" |
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 datetime | |
from collections import OrderedDict | |
import couchdbkit as cdb | |
import argparse | |
import nmap | |
import sys | |
db = None | |
p = argparse.ArgumentParser() |
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/env python | |
from random import shuffle | |
from itertools import izip_longest | |
POOL_NAMES = ("Pool 1", "Pool 2") | |
if __name__ == "__main__": |
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 log_function_call(func): | |
""" | |
Function decorator to output the function name and arguments to logger.debug | |
""" | |
def inner(*args, **kwargs): | |
args_str = ", ".join([str(x) for x in args]) if args else "" | |
kwargs_str = ", ".join( | |
["%s=%s" % (str(key), str(value)) for key, value in kwargs.items()]) if kwargs else "" | |
all_args_str = args_str | |
if all_args_str and kwargs_str: |
NewerOlder