Skip to content

Instantly share code, notes, and snippets.

@ctlllll
ctlllll / longest_chinese_tokens_gpt4o.py
Created May 13, 2024 19:53
Longest Chinese tokens in gpt4o
import tiktoken
import langdetect
T = tiktoken.get_encoding("o200k_base")
length_dict = {}
for i in range(T.n_vocab):
try:
length_dict[i] = len(T.decode([i]))
except:
@peltho
peltho / svelte.md
Last active May 16, 2024 03:44
Svelte cheatsheet
@DamnedFacts
DamnedFacts / mount_vdi.sh
Created May 15, 2019 16:38
Mount a VirtualBox Virtual Disk Image (VDI) on a Mac using hdiutil
#!/bin/sh
TEMP="$1.$$.img"
trap "rm -f $TEMP 2>/dev/null" 1 2 3 11 15
offset=`hexdump -s 0x158 -n 4 "$1" | head -1 | awk '{print $5 $4 $3 $2}'`
offset512=`echo "obase=16; ibase=16; $offset / 200" | bc`
ln "$1" "$TEMP"
hdiutil attach "$TEMP" -nomount -section "0x$offset512"
rm -f "$TEMP"
@jackygu2006
jackygu2006 / ordinals...Inscription.sol
Created May 31, 2023 09:50
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./Logarithm.sol";
import "./TransferHelper.sol";
// This is common token interface, get balance of owner's token by ERC20/ERC721/ERC1155.
interface ICommonToken {
function balanceOf(address owner) external returns(uint256);
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@chenhunghan
chenhunghan / Install CJK fonts to reMarkable Tablet.md
Last active May 16, 2024 03:40
How to install Noto Sans CJK fonts for reMarkable Tablet

reMarkable is a paper tablet by https://remarkable.com/.

The reMarkable tablet is the best e-paper in the market. However, it does not have built-in support for CJK (Chiniese, Korean and Japanese) users.

Luckily, this could be resolved by installing CJK fonts on the tablet.

  1. Go to Preference > Storage > Enable USB web interface (Beta).
  2. Connect reMarkable with your PC via a microUSB cable.
  3. SSH to the device as user "root" using the password find in Preference > About. e.g. ssh root@10.11.99.1
  4. Download "NotoSansCJK[you language]-Regular.otf" from *note, there is limited space on the device, so do not sue "Super OpenType/CFF Collection (Super OTC)", an language-specific OTC is ok.
@elyezer
elyezer / ring_buffer.sql
Last active May 16, 2024 03:38
How to create a ring buffer table in SQLite
-- Example table
CREATE TABLE ring_buffer (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);
-- Number 10 on where statement defines the ring buffer's size
CREATE TRIGGER delete_tail AFTER INSERT ON ring_buffer
BEGIN
DELETE FROM ring_buffer WHERE id%10=NEW.id%10 AND id!=NEW.id;
END;
@wojteklu
wojteklu / clean_code.md
Last active May 16, 2024 03:36
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@mohanpedala
mohanpedala / bash_strict_mode.md
Last active May 16, 2024 03:33
set -e, -u, -o, -x pipefail explanation
@bricef
bricef / monkey.py
Last active May 16, 2024 03:31
Monkey patching of builtins in Python3
# found this from Armin R. on Twitter, what a beautiful gem ;)
import ctypes
from types import MappingProxyType, MethodType
# figure out side of _Py_ssize_t
if hasattr(ctypes.pythonapi, 'Py_InitModule4_64'):
_Py_ssize_t = ctypes.c_int64
else:
_Py_ssize_t = ctypes.c_int