Skip to content

Instantly share code, notes, and snippets.

View 1f604's full-sized avatar

Professional Computer Toucher ( F Y ) 1f604

View GitHub Profile
@1f604
1f604 / settings.json
Created October 23, 2023 08:48
My vscode settings
{
"workbench.colorTheme": "GitHub Dark",
"terminal.integrated.persistentSessionScrollback": 100000,
"terminal.integrated.scrollback": 1000000,
"terminal.integrated.allowChords": false,
"files.trimTrailingWhitespace": true,
"window.zoomLevel": 2,
"gopls": {},
"go.lintTool": "golangci-lint"
}
@1f604
1f604 / hoedown toc rewriter.py
Created March 6, 2022 15:38
hoedown toc rewriting script
# this script was tested to work with Hoedown 3.0.7.
from collections import defaultdict
import subprocess
import re
p = re.compile(r'^(<a href="#toc_[0-9]+">)(.+)(<\/a>\n)$')
# takes a bunch of html lines starting and ending with ul tags
# return a single html string starting and ending with div tags
def rewrite_toc(lines):
@1f604
1f604 / wikipedia toc CSS.html
Last active March 6, 2022 13:11
HTML + CSS to achieve wikipedia style table of contents
<head>
<style>
/* CSS for wikipedia style table of contents */
html {
font-family: sans-serif;
}
.toc {
display: table;
@1f604
1f604 / apply_patch.py
Last active February 11, 2022 23:07
#!/usr/bin/env python
# coding=utf-8
# License: Public domain (CC0)
# Isaac Turner 2016/12/05
# 1f604 2022/02/11
from __future__ import print_function
import difflib
import re
@1f604
1f604 / unifieddiff.py
Created February 11, 2022 18:58 — forked from noporpoise/unifieddiff.py
Apply unified diff patches in pure python2/3
#!/usr/bin/env python
# coding=utf-8
# License: Public domain (CC0)
# Isaac Turner 2016/12/05
from __future__ import print_function
import difflib
import re
@1f604
1f604 / elastic_launch_kill_loop.py
Created January 23, 2022 15:07
Launch elasticsearch in a loop
# change these as needed
MAX_RAM_USAGE = 4 # GB
ELASTIC_BINARY_LOCATION = "/home/x/elasticsearch-7.16.3/bin/elasticsearch"
LOG_FILE = "./log.txt"
from multiprocessing import Process
import subprocess
import os
import requests
from time import sleep
@1f604
1f604 / launch_elastic.py
Last active January 22, 2022 23:21
Launch elastic search from Python
from multiprocessing import Process
import os
import requests
from time import sleep
def f(name):
print('hello! RUNNIGN ELASTIC!', name)
os.system('ES_JAVA_OPTS="-Xms2g -Xmx2g" /home/x/elasticsearch-7.16.3/bin/elasticsearch')
def monitor():
@1f604
1f604 / stat poll file.go
Created June 20, 2021 21:52
file stat poll golang
import (
"fmt"
"io"
"log"
"os"
"time"
)
func main() {
@1f604
1f604 / golang token based apns push notification.go
Last active June 18, 2021 23:13
golang push notification apple apns http2 token-based
// Code to send push notifications. Most of the code is taken from https://github.com/sideshow/apns2/
// I wrote this because I didn't want to use any 3rd party dependencies.
package main
import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/rand"
@1f604
1f604 / swift to golang aes gcm encryption
Last active June 16, 2021 21:25
Swift to golang AES-GCM encryption decryption working example code
// The following code has been tested. It compiles and works.
// Swift code
func encrypt(input: [UInt8]) -> Data? {
let key = SymmetricKey(size: .bits256)
let key64 = key.withUnsafeBytes {
return Data(Array($0)).base64EncodedString()
}
print("key64:", key64)
var sealedBox: AES.GCM.SealedBox