Skip to content

Instantly share code, notes, and snippets.

@cassc
cassc / decorator-func.py
Created September 16, 2021 01:41
Python decorator sample usage
def ignore_error(func):
def myfunc(*args, **kwargs):
try:
func(*args, **kwargs)
except Exception:
print('Error ignored')
traceback.print_exc(file=sys.stdout)
return myfunc
@ignore_error
@cassc
cassc / hid-power.py
Created October 4, 2021 03:22
Capture power button event
import evdev
import subprocess
from evdev import InputDevice, categorize
# To find the path, use `evtest`
dev = InputDevice('/dev/input/event2')
def ignore_error(func):
def myfunc(*args, **kwargs):
try:
func(*args, **kwargs)
@cassc
cassc / github.py
Last active May 10, 2023 07:10
Clone all of your github repos
#!/usr/bin/python
# Clone all repos from github.
# Usage:
# python3 github.py -t [GITHUB_TOKEN] -o [OUTPUT_DIR] -k [PROJECT_OWNER]
from requests.auth import HTTPBasicAuth
import requests
import os
repos = set()
@cassc
cassc / bitbucket.py
Created October 5, 2021 01:39
Clone all repositories from Bitbucket
# Shallow clone all repos from bitbucket.
# Usage:
# python3 bitbucket.py -u [USERNAME] -p [BITbucket_APP_TOKEN] -o [OUTPUT_DIR]
# Requirements:
# 1. Setup app password in Bitbucket
# 2. Setup local ssh keys
# 3. Only git repositories are supported
from requests.auth import HTTPBasicAuth
import requests
@cassc
cassc / broadcaster.py
Last active October 7, 2021 03:47
Send UDP broadcast and read replies from all clients
# Send UDP broadcast and read reply
# Edited from
# https://gist.github.com/ninedraft/7c47282f8b53ac015c1e326fffb664b5
import socket
import time
import binascii
import _thread as thread
@cassc
cassc / st7735s-pi.py
Created October 9, 2021 07:08
ST7735S on Raspberry Pi
# Connections:
# LED-K : GND
# LED-A : GPIO2
# RESET : GPIO25
# DCX : GPIO24
# SDA : GPIO10
# SCL : GPIO11
# VDDI : 3.3V
# VDD : 3.3V
# CS : GPIO8
@cassc
cassc / .dir-locals.el
Created October 30, 2021 06:44
sample dir locals file for deps edn project
((clojure-mode . ((cider-preferred-build-tool . clojure-cli)
;; you can specify multiple profiles to use
(cider-clojure-cli-global-options . "-M:dev:local:reloaded:inspect/reveal-nrepl-cider")
(cider-jack-in-dependencies . nil)
(cider-jack-in-nrepl-middlewares . nil)
(cider-jack-in-lein-plugins . nil)
(cider-clojure-cli-parameters . ""))))
@cassc
cassc / GetExternalIP.go
Created November 8, 2021 03:31
Get external IP in go
func GetExternalIP() (string, error) {
ifaces, err := net.Interfaces()
if err != nil {
return "", err
}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 {
continue // interface down
}
if iface.Flags&net.FlagLoopback != 0 {
@cassc
cassc / GetMac.go
Created November 8, 2021 03:31
Get list of MAC addresses in Go
func GetMac() ([]string, error) {
ifas, err := net.Interfaces()
if err != nil {
return nil, err
}
var as []string
for _, ifa := range ifas {
a := ifa.HardwareAddr.String()
if a != "" {
as = append(as, a)
# github code search
#
# Usage:
# python3 github-search.py -l rs -t Code ethers contract
import subprocess
from urllib.parse import quote_plus
import argparse
BROWSER_CLI = 'brave'