Skip to content

Instantly share code, notes, and snippets.

View toast254's full-sized avatar
🐧

toast254 toast254

🐧
View GitHub Profile
@marcan
marcan / rpi_cam_auth.py
Created January 25, 2019 07:48
Raspberry Pi Camera V2 DRM authentication example
import hmac, hashlib
# Data from I²C trace at https://hackaday.io/project/19480-raspberry-pi-camera-v21-reversed/log/52547-i2c-logic-analyzer-trace
# Secret key from VideoCore blob
# serial[8], serial[7:4], serial[3:0]
serial = bytes.fromhex("EE8C196D8301230B59")
# rPi -> camera random number
numIn = bytes.fromhex("5805F3C898C3133154498E082F2E703516F2DBD1")
# -*- coding: utf-8 -*-
def pretty_print_file_size(file_size: int, use_base_2: bool = True, approximate: bool = True, suffix: str = 'B'):
"""
Output a file size as a human friendly str.
:param file_size: file size in bits to pretty print
:param use_base_2: choose between base 10 (False) or base 2 (True, default) divider
:param approximate: drop the float part of the result (True, default)
#!/bin/bash
###############################
# to deactivate this script
# uncomment the following line
# and reboot
exit 0
###############################
function clear_screen {
#!/bin/bash
#*********************************************************************
# Configuration
#*********************************************************************
DEF_GATEWAY="192.168.1.2" # default route
BCK_GATEWAY="192.168.1.1" # backup route
RMT_IP_1="8.8.8.8" # first remote ip to test
RMT_IP_2="8.8.4.4" # second remote ip to test
PING_TIMEOUT="15" # ping timeout in seconds
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import csv
import psycopg2
# Connection details:
dbname = 'sampledb'
user = 'postgres'
# -*- coding: utf-8 -*-
import os
import json
import logging
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
logger = logging.getLogger(__name__)
# -*- coding: utf-8 -*-
import time
import threading
class ThreadedClass(object):
""" Threading example class.
The run() method will be started and it will run in the background
@toast254
toast254 / dict_merge.py
Last active May 16, 2017 13:39 — forked from angstwad/dict_merge.py
Recursive dictionary merge in Python 3
# -*- coding: utf-8 -*-
import collections
def dict_merge(dct: dict, merge_dct: dict):
""" Recursive dict merge. Inspired by :meth:``dict.update()``, instead of
updating only top-level keys, dict_merge recurses down into dicts nested
to an arbitrary depth, updating keys. The ``merge_dct`` is merged into
``dct``.
# -*- coding: UTF-8 -*-
import os
import csv
import logging
logger = logging.getLogger(__name__)
def read_csv(file: str = 'in.csv', skip_title: bool = True):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from tornado import httpserver, ioloop, netutil, process, web, options
# app's title
__title__ = 'Example'
options.define('port', default=8080, help='run on the given port', type=int)