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 / 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 / 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
@groz
groz / sync-http.swift
Created February 15, 2018 22:29
Synchronous http request in Swift
import Foundation
func query(address: String) -> String {
let url = URL(string: address)
let semaphore = DispatchSemaphore(value: 0)
var result: String = ""
let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
result = String(data: data!, encoding: String.Encoding.utf8)!
@noporpoise
noporpoise / unifieddiff.py
Last active November 14, 2023 18:59
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
@leycec
leycec / beartype.py
Last active August 4, 2022 18:22
`@beartype` Decorator and Unit Test Suite Thereof
#!/usr/bin/env python3
'''
`@beartype` decorator, implementing a rudimentary subset of PEP 484-style type
checking based on Python 3.x function annotations.
See Also
----------
https://stackoverflow.com/a/37961120/2809027
Stackoverflow answer introducing the `@beartype` decorator.
@psayre23
psayre23 / gist:c30a821239f4818b0709
Last active May 26, 2024 13:27
Runtime Complexity of Java Collections
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
anonymous
anonymous / matrix_shuffle.py
Created May 13, 2012 14:14
matrix_shuffle.py
"""
Computes the probability distribution of states created by
the shuffle2 algorithm. This should return results similar to
enumerate_shuffle.py.
A state is a 2-tuple: (swapped, deck)
The probability of transitioning from one state to another can be represented by
a Markov matrix M.