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 March 30, 2020 10:16
Binary file diff
#!/usr/bin/env python
"""
Binary file diff
Usage:
bindiff <FILE> <FILE>
Install:
curl -L https://gist.githubusercontent.com/guyskk/98621a9785bd88cf2b4e804978950122/raw/b933874153efe018538ff2050cb27d1a948246e2/bindiff.py -o bindiff && chmod +x bindiff
"""
import sys
import io
@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 |
        |      |           |          |                    |
        +--->  +-----------+----------+------+             |