Skip to content

Instantly share code, notes, and snippets.

@xyb
xyb / audio-volumes.py
Last active February 17, 2023 03:23
get audio volumes samples, assited by ChatGPT
from pydub import AudioSegment
import numpy as np
def get_volumes(audio_path, format, chunks_number=100):
audio = AudioSegment.from_file(audio_path, format=format)
segment_length = len(audio) // chunks_number
volumes = []
for i in range(chunks_number):
@xyb
xyb / 00-install-facetime-camera.sh
Last active November 23, 2024 14:12 — forked from ukn/99-install-facetime-camera.sh
Install the kernal module required for the facetimehd camera to work on Linux
#!/bin/bash
set -e
export CONFIG_MODULE_SIG=n
export CONFIG_MODULE_SIG_ALL=n
# For current kernel
export KERNELRELEASE=$(cat /proc/version | awk '{print $3}')
temp_dir=$(mktemp -d)
echo "Installing FacetimeHD camera for $KERNELRELEASE"
@xyb
xyb / crx2zip.nim
Last active January 11, 2022 04:07
Convert CRX to zip file
# Convert CRX to zip file.
# Inspired by https://github.com/peerigon/unzip-crx/blob/master/src/index.js
# nim c -d:release --gc:none --stackTrace:off --lineTrace:off --opt:size uncrx.nim
import system
import os
import streams
import strutils
const
zipMagicNumber = "PK\x03\x04"
@xyb
xyb / gist:8a9ee3b116dcc51be8f5b65ee0e57df4
Last active November 21, 2021 07:30
post github issue faild
@xyb
xyb / docker-save.sh
Created July 2, 2020 08:06
save docker image to a compressed tar ball
#!/bin/sh
image="$1"
tarfile=$(echo "$image" | sed -e 's:/:--:g' -e 's/$/.tar/')
tgzfile=$(echo "$tarfile" | sed -e 's/$/.gz/')
docker save "$image" -o "$tarfile"
gzip "$tarfile"
echo "$image" saved to "$tgzfile"
@xyb
xyb / sqlite-kv-restful.py
Last active July 1, 2020 04:10 — forked from georgepsarakis/sqlite-kv-restful.py
Simple SQLite-backed key-value storage Rest API. Built with Flask & flask-restful.
#!/usr/bin/env python3
"""
Requirements:
pip install Flask==1.1.2 Flask-RESTful==0.3.8
"""
import os
import sqlite3
from datetime import datetime
def format_local_datetime(dt):
"""Return a string with local timezone representing the date."""
try:
return dt.astimezone().strftime('%Y-%m-%d %H:%M %z')
except (TypeError, ValueError):
# Python 2 do not have builtin timezone
import time
def get_timezone_offset():
@xyb
xyb / cdctool.py
Created February 28, 2020 06:03
A tool help to compare huge files by splitting them into small content-based chunks.
#!/usr/bin/env python3
# Usage: python3 cdctools.py <data_file> [<chunk_size>]
# Usage: MORE_DETAILS=1 python3 cdctools.py <data_file> [<chunk_size>]
import os
import sys
import fastchunking
READ_BUFFER_SIZE = 1024 * 4
@xyb
xyb / pyinstrument_json_to_flamegraph.py
Created October 31, 2019 08:10
Convert github.com/joerick/pyinstrument's json format to flamegraph
#!/usr/bin/env python3
# Author: Xie Yanbo <[email protected]>
import json
USE_LONG_FILE_PATH = True
def to_flamegraph(pyinst_data):
def walk(data):
@xyb
xyb / cookiemonster.go
Last active February 3, 2019 15:41 — forked from rwifeng/cookiemonster.go
Simple script to extract (encrypted) cookies out of Chrome OS X cookie store. Usage: ./cookiemonster domain.com
package main
import (
"golang.org/x/crypto/pbkdf2"
"crypto/aes"
"crypto/cipher"
"crypto/sha1"
"database/sql"
"fmt"
"log"