Skip to content

Instantly share code, notes, and snippets.

@wojteklu
wojteklu / clean_code.md
Last active May 14, 2024 10:48
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

@Kartones
Kartones / postgres-cheatsheet.md
Last active May 14, 2024 10:48
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@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:
@YuMS
YuMS / update-git.sh
Created June 29, 2016 09:28
Update git to latest version on Ubuntu
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
@OhMeadhbh
OhMeadhbh / 00_readme.txt
Last active May 14, 2024 10:44
Efficiently Calculating the Parity of a 32 Bit Integer
Read this file first.
Then read the comments at the top of parity_test.c
Then read the comments above each algorithm implementation in parity.c
So there I was talking about efficient implemetation of fundamental functions
with Palmer over at SiFive. Back in the day, I used to participate in informal
contests on rec.games.programmer to see who could craft the most efficient
implementations for population count or bit reversal or bit-blitting. For
programmer types, it's great fun.
@LeviSnoot
LeviSnoot / discord-timestamps.md
Last active May 14, 2024 10:42
Discord Timestamp Syntax

Discord Timestamps

Discord timestamps can be useful for specifying a date/time across multiple users time zones. They work with the Unix Timestamp format and can be posted by regular users as well as bots and applications.

The Epoch Unix Time Stamp Converter is a good way to quickly generate a timestamp. For the examples below I will be using the Time Stamp of 1543392060, which represents November 28th, 2018 at 09:01:00 hours for my local time zone (GMT+0100 Central European Standard Time).

Formatting

Style Input Output (12-hour clock) Output (24-hour clock)
Default <t:1543392060> November 28, 2018 9:01 AM 28 November 2018 09:01
@ZCube
ZCube / Ajazz_Stream_Deck_Protocol.md
Created May 13, 2024 17:53
Notes on the Ajazz Stream Deck HID protocol

Ajazz Stream Deck Protocol

How to interface with a Ajazz Stream Deck device.

Synopsis

The device uses the HID protocol to communicate with its software.

Configuration

The number of keys can be determined from the HID device descriptors. There is currently no known provision to determine their layout or size. The buttons on the current version of the device (AKP153)

@itswzyss
itswzyss / gumroad_bulk_download.js
Last active May 14, 2024 10:42
Bulk Download Gumroad Library
// In light of the TOS change at Gumroad, I've modified a script by @Fhurai that will categorize all the download links with their
// original asset page. In order to use this, navigate to https://app.gumroad.com/library and open your DevTools. Then paste the
// following code into the Console. See more info at https://blog.wzyss.dev/easily-archive-your-gumroad-library/
async function fetchUrls(link) {
// Fetch and process URLs from the given link
return fetch(link)
.then(res => res.text())
.then(text => {
let parser = new DOMParser();
@thomasbnt
thomasbnt / code_colors_discordjs.md
Last active May 14, 2024 10:42
Code colors for embed discord.js

Here is an updated list of the colors that are currently implemented with a name. To using colors on discord.js, this is a typedef Colors, Colors.Aqua to get the Aqua color.

Name Int value Hex Code
Default 0 #000000
Aqua 1752220 #1ABC9C
DarkAqua 1146986 #11806A
Green 5763719 #57F287
DarkGreen 2067276 #1F8B4C