Skip to content

Instantly share code, notes, and snippets.

@KD-MM2
KD-MM2 / .clang-format
Created June 18, 2024 15:58
clang-format for logos(Objective-C) using within theos-formatter
# Format Style Options
---
BasedOnStyle: WebKit
AllowShortIfStatementsOnASingleLine: WithoutElse
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
ColumnLimit: 250
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
IndentWidth: 4
@KD-MM2
KD-MM2 / 1_otp.ts
Created May 4, 2024 14:56 — forked from matteobertozzi/1_otp.ts
Generate Time Based OTP in Javascript/Typescript, Python, Java
async function generateOneTimePassword(rawKey: Uint8Array, counter: number): Promise<number> {
const data = new DataView(new ArrayBuffer(8));
data.setBigUint64(0, BigInt(Math.floor(counter)), false);
const algo = { name: 'HMAC', hash: 'SHA-1' };
const key = await crypto.subtle.importKey('raw', rawKey, algo, false, ['sign']);
const hmacHash = new Uint8Array(await crypto.subtle.sign(algo, key, data.buffer));
const offset = hmacHash[hmacHash.byteLength - 1] & 0x0f;
const hotp = (hmacHash[offset] & 0x7f) << 24
@KD-MM2
KD-MM2 / broken-lcd-laptop-as-a-server.sh
Created May 5, 2023 15:57
Broken LCD Laptop as a server. A laptop with broken lcd with linux installed. Even the power settings is set to NEVER turn off, the laptop just keep wake only HDMI cable is plugged. Here is how to solve.
# Open the Terminal by pressing Ctrl+Alt+T.
# Type the following command to edit the power management configuration file:
sudo nano /etc/systemd/logind.conf
# Find the following line in the file:
#HandleLidSwitch=suspend
# Uncomment the line by removing the "#" at the beginning of the line and change "suspend" to "ignore":
HandleLidSwitch=ignore
@KD-MM2
KD-MM2 / decode-base64-and-write-to-file.py
Last active April 8, 2023 20:06
decode base64 and write to file python
import os
import base64
files_size_under_1MB = {
"file_name_1": "file-1_encoded_base64",
"file_name_1": "file-2_encoded_base64"
}
for keys in files_size_under_1MB:
try: os.remove(keys) # remove the old file
except: pass
@KD-MM2
KD-MM2 / parse-format_number.py
Last active April 8, 2023 20:02
parse number and format number
# fmt_num(1000)
# result: 1M
# type(fmt_num(1000))
# result: <class 'str'>
def fmt_num(num):
suffixes = ["", "K", "M", "B", "T"]
suffix_index = 0
while abs(num) >= 1000 and suffix_index < len(suffixes)-1:
suffix_index += 1 # increment the suffix index
num /= 1000.0 # divide by 1000 to get the number in the next magnitude
@KD-MM2
KD-MM2 / github_ssl_verify_request_get_python.py
Last active April 8, 2023 20:03
github ssl verify request get python
import requests
import base64
# replace with your personal access token(classic)
github_pat = "ghp_abcdfeghi......"
# encode pat using base64
encoded = base64.base64encode(github_pat.encode())
# check the encoded base64