Skip to content

Instantly share code, notes, and snippets.

View ka7eh's full-sized avatar

Kaveh Karimi-Asli ka7eh

View GitHub Profile
@ka7eh
ka7eh / swap-settings.md
Last active November 18, 2020 21:15
Modify swap files

Add a swap file:

Create a file (you can replace /swapfile with another location and filename): sudo fallocate -l 1G /swapfile
Change its permissions: sudo chmod 600 /swapfile
Mark the new file as swap space: sudo mkswap /swapfile
Enable the swap file: sudo swapon /swapfile
Check and see if the file is enabled: swapon --show
Update fstab to make your changes permanent (you might want to create a backup of the existing fstab): echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Adjust swappiness, if needed:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ka7eh
ka7eh / useElementRect.ts
Created August 12, 2020 18:28
A custom React hook that returns an object containing an element's position and size attributes. The object gets updated on window resize.
type ElementRect = {
width: number | null;
height: number | null;
top: number | null;
right: number | null;
bottom: number | null;
left: number | null;
marginTop: number | null;
marginRight: number | null;
marginBottom: number | null;