Skip to content

Instantly share code, notes, and snippets.

View hitrust's full-sized avatar

hitrust hitrust

View GitHub Profile
{% macro render_pagination(
pagination,
endpoint=None,
prev=('«')|safe,
next=('»')|safe,
size=None,
ellipses='…',
args={},
fragment='',
align=''
@hitrust
hitrust / pagination_macros.html
Created May 18, 2024 07:09 — forked from allhailwesttexas/pagination_macros.html
Flask/Jinja2 macro for rendering pagination in a template with Bootstrap components. Can center the component by wrapping in <nav class="text-center">.
{% macro render_pagination(pagination, endpoint) %}
<ul class="pagination">
{% if pagination.has_prev %}
<li>
<a href="{{ url_for(endpoint, page=pagination.prev_num) }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
@hitrust
hitrust / s3_client_sync_download_folder.py
Created May 15, 2023 00:34 — forked from a-canela/s3_client_sync_download_folder.py
Directory download (sync) through boto3 supporting include-only pattern
import os
import boto3
from fnmatch import fnmatch
from botocore.config import Config
from traceback import format_exc
from multiprocessing import Process, Queue, Pipe
from concurrent.futures import ThreadPoolExecutor
class DownloadException(Exception):
@hitrust
hitrust / extractdocx.py
Created September 30, 2022 15:20 — forked from etienned/extractdocx.py
Simple function to extract text from MS XML Word document (.docx) without any dependencies.
try:
from xml.etree.cElementTree import XML
except ImportError:
from xml.etree.ElementTree import XML
import zipfile
"""
Module that extract text from MS XML Word document (.docx).
(Inspired by python-docx <https://github.com/mikemaccana/python-docx>)
@hitrust
hitrust / stablediffusionwalk.py
Created August 17, 2022 02:24 — forked from karpathy/stablediffusionwalk.py
hacky stablediffusion code for generating videos
"""
draws many samples from a diffusion model by slerp'ing around
the noise space, and dumps frames to a directory. You can then
stitch up the frames with e.g.:
$ ffmpeg -r 10 -f image2 -s 512x512 -i out/frame%04d.jpg -vcodec libx264 -crf 10 -pix_fmt yuv420p test.mp4
THIS FILE IS HACKY AND NOT CONFIGURABLE READ THE CODE, MAKE EDITS TO PATHS AND SETTINGS YOU LIKE
THIS FILE IS HACKY AND NOT CONFIGURABLE READ THE CODE, MAKE EDITS TO PATHS AND SETTINGS YOU LIKE
THIS FILE IS HACKY AND NOT CONFIGURABLE READ THE CODE, MAKE EDITS TO PATHS AND SETTINGS YOU LIKE
@hitrust
hitrust / .git-commit-template.txt
Created July 21, 2022 01:55 — forked from adeekshith/.git-commit-template.txt
This commit message template helps you write great commit messages and enforce it across teams.
# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<---- Using a Maximum Of 50 Characters ---->|
# Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
@hitrust
hitrust / typeofvar.sh
Created May 25, 2022 01:57 — forked from CMCDragonkai/typeofvar.sh
Bash: Get the type of a variable
#!/usr/bin/env bash
typeofvar () {
local type_signature=$(declare -p "$1" 2>/dev/null)
if [[ "$type_signature" =~ "declare --" ]]; then
printf "string"
elif [[ "$type_signature" =~ "declare -a" ]]; then
printf "array"

利用 NGINX 的 Stream 模塊 sni_preread 功能,可以做到讓 Trojan 和其他網站在同一台機器上共享 443 端口。

@hitrust
hitrust / app.py
Created April 25, 2021 01:30 — forked from tombulled/app.py
Stream a file, in this case an mp4 video, supporting range-requests using starlette
from starlette.applications import Starlette
from starlette.responses import StreamingResponse
from starlette.requests import Request
from starlette.routing import Route
from pathlib import Path
from typing import IO, Generator
"""
Stream a file, in this case an mp4 video, supporting range-requests using starlette
@hitrust
hitrust / comments-trick.json
Created June 5, 2020 03:12 — forked from MoOx/comments-trick.json
How to make comment in JSON file
{
"//field": "These 'double quote' 'double quote' are used as comments, because JSON doesnt' allow comment",
"field": {},
"#another-field": "Another comment",
"another-field": {},
"/*stuff": "Be careful to use them when you have full control of the content :)",
"stuff": [],
"bla": "bla"
}