Skip to content

Instantly share code, notes, and snippets.

@guyskk
guyskk / typechat.py
Created April 5, 2024 08:15
TypeChat让AI输出结构化数据
import json
import logging
import re
import js2py
LOG = logging.getLogger(__name__)
RE_CODE_BLOCK = re.compile(
r'```(json)?\n?(.+)\n?```', re.MULTILINE | re.DOTALL
@guyskk
guyskk / memory-monitor-jupyterhub.service
Last active May 11, 2023 12:23
Monitor system memory and execute recover command when OOM
[Unit]
Description=memory-monitor-jupyterhub
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=root
// https://www.uscreditcards101.com/wp-content/cache/autoptimize/js/autoptimize_9a2cfd2fee7b6b64b5fa19e57f03bc6c.js
// https://www.uscreditcards101.com/how-to-use-plastiq-bill-pay/
// https://www.v2ex.com/t/752795#reply113
$(document).ready(function () {
setTimeout(function () {
var observer = new IntersectionObserver(
function (entries, observer) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
var options = JSON.parse(entry.target.getAttribute("data-options"));
"""
table:
book_id, tag_id, weight, boom
insert/update:
boom = boomfilter(book_tag_ids)
select:
q = boomfilter(query_tag_ids)
select * from table
@guyskk
guyskk / iotest.py
Created June 10, 2020 15:05
IO performance test
import os
import random
import timeit
def random_content():
return os.urandom(random.randint(1, 10) * 1024)
file = open('test.db', 'wb')
@guyskk
guyskk / bindiff.py
Last active August 26, 2024 07:25
bindiff: Binary file diff
#!/usr/bin/env python
"""
Binary file diff
Usage:
bindiff <FILE> <FILE>
Install:
curl -L https://gist.githubusercontent.com/guyskk/98621a9785bd88cf2b4e804978950122/raw/efc200c6e45c3ef503249cf3b151fb8a1f5b75cb/bindiff.py -o bindiff && chmod +x bindiff
"""
import io
import sys
@guyskk
guyskk / pandas_parallel.py
Created December 16, 2018 03:20
pandas parallel
"""
Requirements:
pip install pandas msgpack dask tqdm loguru
Usage:
import pandas as pd
from pandas_parallel import pandas_parallel
df = pd.DataFrame.from_records([
['A', 1, 2],
@guyskk
guyskk / .pythonrc.py
Last active May 25, 2020 11:15
Add command history and tab completion to python shell.
"""
Add command history and tab completion to python shell.
1. Save this file in ~/.pythonrc.py
2. Add the following line to your ~/.bashrc:
export PYTHONSTARTUP="$HOME/.pythonrc.py"
"""
def _enable_history_and_completer():
@guyskk
guyskk / non_blocking.py
Created July 8, 2018 03:12
Non-blocking will block on busy syscall!
"""
Non-blocking will block on busy syscall!
两条数据流形成一个环,预先填充128字节数据。
Producer和Consumer驱动数据在环中流动。
+----------------+
| |
+ v
producer consumer
               +-------------------------------------------+
               |                                           |
               |                 application               |
               |                                           |
        +--->  +-----------+-----------                    |
        |      |           |          |                    |
  api   |      | curio-api | trio-api |  asyncio-libraries |
        |      |           |          |                    |
        +--->  +-----------+----------+------+             |