Skip to content

Instantly share code, notes, and snippets.

@SakuraHentai
SakuraHentai / crc64_be.js
Last active October 4, 2023 05:29
crc64
// ref: https://github.com/torvalds/linux/blob/master/lib/crc64.c#L51
function crc64(str) {
const CRC64_ECMA182_POLY = 0x42f0e1eba9ea3693n
// CRC64 lookup table
const crc64Table = []
for (let i = 0n; i < 256n; i++) {
let crc = 0n
let c = i << 56n
@henryivesjones
henryivesjones / postgresql_date_timestamp_interval_cheat_sheet.md
Created February 14, 2023 16:56
PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.

Types

PostgreSQL Date/Time Documentation

DATE

The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.

TIMESTAMP

The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.

@D2theR
D2theR / README.md
Last active February 28, 2024 17:34
Auto-generates Serializers & ModelViewSets in a Django API using just models

Why?

I got sick of writing the same Serializer & ModelViewSet classes over and over so I found and wrote some code to do it for me, and somehow it works! Please note that there are a lot of caveats to running an API like this and while this may work, I know there's A LOT of room for improvement, feel free to fork and help!

USAGE

Import the router module to your main sites urls.py file as the injection point like so... Make sure to remove any other imports from other viewsets that you don't need that may conflict!

@marcelrv
marcelrv / _docker-migrate-aufs.md
Last active September 2, 2024 13:23
Docker migrate to overlay2 from aufs script

Docker migrate to overlay2 from aufs script

Crazy that this is pretty much forced change without proper transition script

note. Based on https://www.sylvaincoudeville.fr/2019/12/docker-migrer-le-stockage-aufs-vers-overlay2/ NOT WORKING!!!! IF FOLLOWING THE ABOVE.. SOMEHOW THE CONTAINERS DO NOT RE-APPEAR!

The only way I found that is somewhat automated is the the docker-compose way..

Which is still not 100% and require manual fixing of stupid errors of the docker-compose tool (mainly things that ere not interpreted right, like dates & userIds that need to manually surrounded by quotes etc)

@Daenero
Daenero / quill-fix-indent.ts
Created November 13, 2020 14:29
Fix for Quill.js issue with list indent (use of css class instead of pure HTML)
// https://github.com/quilljs/quill/issues/979
interface NestedElement {
content: string;
indent: number;
classes: string;
}
export function quillDecodeIndent(text: string) {
if (!text || text.length === 0) {
#auto adjusting column width of cells for openpyxl 3.0
for column_cells in ws.columns:
unmerged_cells = list(filter(lambda cell_to_check: cell_to_check.coordinate not in ws.merged_cells, column_cells))
length = max(len(str(cell.value)) for cell in unmerged_cells)
ws.column_dimensions[unmerged_cells[0].column_letter].width = length * 1.2
@heysamtexas
heysamtexas / docker-compose.yml
Created January 29, 2020 01:07
Pristine config for Traefik 2.0, Docker, and LetsEncrypt with sample container. Includes a HTTP to HTTPS redirect
version: '3'
services:
traefik:
container_name: traefik
image: traefik:v2.0
command:
- "--api.insecure=true"
- "--providers.docker=true"
@rhcarvalho
rhcarvalho / go.mod
Last active October 21, 2024 13:37
Example of using sentry-go and go-chi
module sentry.io/go/chi-example
go 1.13
require (
github.com/getsentry/sentry-go v0.4.0
github.com/go-chi/chi v4.0.3+incompatible
)
@mslinn
mslinn / cronTest
Last active September 27, 2023 10:35
Run a cron job manually and immediately
#!/bin/bash
# Execute a user crontab entry with the proper environment
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
env -i bash --noprofile --norc -c "$DIR/cronTest2 $USER"
@samirreza
samirreza / changeRemoteUrl.sh
Created April 19, 2019 13:16
Shell script to bulk change git remote url
directoryContainingAllRepos="" # directory containing all git repo's
oldGitRemoteServer="" # current remote server url for example gitlab.com
newGitRemoteServer="" # new remote server url for example git.example.com
cd $directoryContainingAllRepos
find * -maxdepth 0 -type d \( ! -name . \) -print | while read dir
do
cd $dir
if [ -d ".git" ]
then
remoteUrl1="$(git config --get remote.origin.url)"