Skip to content

Instantly share code, notes, and snippets.

import random
N = 4 # Number of chores
p = 2 # Number of players
preferences = []
for i in range(p):
vs = list(range(N))
random.shuffle(vs)
preferences.append(vs)
@samsch
samsch / stop-using-jwts.md
Last active October 3, 2024 22:31
Stop using JWTs

Stop using JWTs!

TLDR: JWTs should not be used for keeping your user logged in. They are not designed for this purpose, they are not secure, and there is a much better tool which is designed for it: regular cookie sessions.

If you've got a bit of time to watch a presentation on it, I highly recommend this talk: https://www.youtube.com/watch?v=pYeekwv3vC4 (Note that other topics are largely skimmed over, such as CSRF protection. You should learn about other topics from other sources. Also note that "valid" usecases for JWTs at the end of the video can also be easily handled by other, better, and more secure tools. Specifically, PASETO.)

A related topic: Don't use localStorage (or sessionStorage) for authentication credentials, including JWT tokens: https://www.rdegges.com/2018/please-stop-using-local-storage/

The reason to avoid JWTs comes down to a couple different points:

  • The JWT specification is specifically designed only for very short-live tokens (~5 minute or less). Sessions
@YumaInaura
YumaInaura / 00_README.md
Last active June 9, 2024 17:39
Golang — Understanding channel, buffer, blocking, deadlock and happy groutines.

Golang — Understanding channel, buffer, blocking, deadlock and happy groutines.

I was so confused to understand behaviior of Golang channels, buffer, blocking, deadlocking and groutines.

I read Go by Example topics.

@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active September 20, 2024 14:24
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@timvisee
timvisee / falsehoods-programming-time-list.md
Last active October 19, 2024 07:05
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@aantron
aantron / fragment of java.cpp
Created January 9, 2017 18:09
Java classes inlined into object file, plus loader
// This function calls the JNI routine DefineClass for each class in the
// in-memory class table (see java-classes.h). The class loader parameter passed
// to define class is the result of calling ClassLoader.getSystemClassLoader().
jthrowable java_load_classes()
{
JNIEnv *environment;
jclass class_loader;
jmethodID get_system_loader;
jobject system_loader;
jthrowable exception;
@nhomble
nhomble / scraper.py
Created September 25, 2015 23:52
playing with web scraper (Beautiful Soup) to expose BodyBuilding.com's exercise database (to later be turned into a restful service maybe)
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import pycurl
from io import BytesIO
import re
import sys
END = "abcdefghijklmnopqrstuvwxyz0123456789"
BB_URL = "http://www.bodybuilding.com/exercises/list/index/selected/"
@psayre23
psayre23 / gist:c30a821239f4818b0709
Last active October 1, 2024 02:03
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
@UnquietCode
UnquietCode / RecyclingObjectPool.java
Created June 5, 2013 21:51
Object pool which reclaims resources not from the user but rather from the garbage collector.
package com.studyblue.utils.pool;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;