Skip to content

Instantly share code, notes, and snippets.

View xnohat's full-sized avatar
💭
Coding like machine

Hong Phuc Nguyen xnohat

💭
Coding like machine
View GitHub Profile
@xnohat
xnohat / indexeddbstorage.js
Created October 5, 2023 04:50
sync wrapper for IndexedDB to same localStorage API, working extractly same as localStorage, just replace localStorage to idbStorage
class IndexedDBStorage {
constructor(dbName = 'localStorageDB', storeName = 'localStorageStore') {
this.dbName = dbName;
this.storeName = storeName;
this._init();
this.cache = {};
}
_init() {
const request = window.indexedDB.open(this.dbName, 1);
@sr229
sr229 / install-anbox-dkms-fedora.sh
Last active December 21, 2023 17:59
Automated Script to Install Anbox Ashmem and Binder to WSL2 Linux Kernel
#!/bin/bash
set -o pipefail
KERNEL_WORKING_DIRECTORY="/usr/src"
KERNEL_VERSION=$(uname -r)
REQUIRED_DEPENDENCIES="git bison flex elfutils-libelf-devel openssl-devel"
KERNEL_SRC_DIR="$KERNEL_WORKING_DIRECTORY/WSL2-Linux-Kernel-$(uname -r)"
echo "Warning: This script has to be run on sudo permissions. If you encounter issues please report it immediately."
@Sitin
Sitin / setup.sh
Last active March 7, 2024 17:10
Run x86-64 Docker images on Raspberry Pi 4 (QEMU/QUS)
# Setup QEMU for x86-64 Docker images on Raspberry Pi 4
# Install Python3 and Docker first: https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl
# Install QUEMU (https://www.qemu.org/)
sudo apt-get install qemu binfmt-support qemu-user-static
# Use QUS in Docker (https://github.com/dbhi/qus) to configure x86_64 architecture
docker run --rm --privileged aptman/qus -s -- -p x86_64
# Test x86-64 image:
@mwufi
mwufi / install_docker_in_colab.sh
Last active April 28, 2024 10:40
Install Docker in Google Colab!
# First let's update all the packages to the latest ones with the following command
sudo apt update -qq
# Now we want to install some prerequisite packages which will let us use HTTPS over apt
sudo apt install apt-transport-https ca-certificates curl software-properties-common -qq
# After that we will add the GPG key for the official Docker repository to the system
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# We will add the Docker repository to our APT sources
@bergmannjg
bergmannjg / rearct-native-app-in-wsl2.md
Last active May 2, 2024 20:45
Building a react native app in WSL2
@pinkhominid
pinkhominid / index.js
Created September 24, 2019 10:15
Upload a file with node-fetch and form-data
const fs = require('fs');
const fetch = require('node-fetch');
const FormData = require('form-data');
const filePath = `path/to/file.ext`;
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('field-name', fileStream, { knownLength: fileSizeInBytes });
@sandren
sandren / tailwind.md
Last active April 26, 2024 12:37
Tailwind CSS best practices

Tailwind CSS best practices

Utility classes

  1. When writing a string of multiple utility classes, always do so in an order with meaning. The "Concentric CSS" approach works well with utility classes (i.e,. 1. positioning/visibility 2. box model 3. borders 4. backgrounds 5. typography 6. other visual adjustments). Once you establish a familiar pattern of ordering, parsing through long strings of utility classes will become much, much faster so a little more effort up front goes a long way!

  2. Always use fewer utility classes when possible. For example, use mx-2 instead of ml-2 mr-2 and don't be afraid to use the simpler p-4 lg:pt-8 instead of the longer, more complicated pt-4 lg:pt-8 pr-4 pb-4 pl-4.

  3. Prefix all utility classes that will only apply at a certain breakpoint with that breakpoint's prefix. For example, use block lg:flex lg:flex-col lg:justify-center instead of block lg:flex flex-col justify-center to make it very clear that the flexbox utilities are only applicable at the

@thomwolf
thomwolf / top-k-top-p.py
Last active January 2, 2024 07:43
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
""" Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
Args:
logits: logits distribution shape (vocabulary size)
top_k >0: keep only top k tokens with highest probability (top-k filtering).
top_p >0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
"""
assert logits.dim() == 1 # batch size 1 for now - could be updated for more but the code would be less clear
top_k = min(top_k, logits.size(-1)) # Safety check
@profiprog
profiprog / simple-compressing.md
Last active January 4, 2024 11:34
Simple compressing base64 string in JavaScript

Story

In needed include base64 encoded simple image into HTML page in two formats:

1st as PNG format has length 196 characters and looks like this:

iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAWElEQVR42mNkwA/qgbgRnwJGAgb8BwI7RkbGw5QYUAs0oGXUAPwGgKKqgYF0ANLTyAi1xhZI2WOYzsjYDJTbC2QewGHIwcERBsPcgHqgAX8pMQAcxfhyIwATTkxL+hgX2QAAAABJRU5ErkJggg==

2nd as CUR format has length 1536 characters and looks like this:

`AAACAAEAEBAAAAcABwBoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///z0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH////98AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////3wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////98AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

@JochemKuijpers
JochemKuijpers / install_synology_drive_on_fedora.sh
Created January 5, 2019 03:40
Installs Synology Drive on Fedora 29 (from the .deb package). Use at own risk.
#!/usr/bin/env bash
if [[ $UID != 0 ]];
then
echo "Please run this script with sudo or as root:"
echo
echo "sudo $0 $*"
exit 1 || return 1
fi