Skip to content

Instantly share code, notes, and snippets.

View bitsmanent's full-sized avatar

Claudio Alessi bitsmanent

View GitHub Profile
@bitsmanent
bitsmanent / msleep.c
Last active December 21, 2022 11:38
Sleep for a specified number of milliseconds
int
msleep(int ms) {
struct timespec req = {0}, rem;
int r = ms / 1000;
if(r >= 1) {
req.tv_sec = r;
ms -= r * 1000;
}
if(ms)
@aileftech
aileftech / hex-colors.txt
Created October 1, 2022 18:10
A Bash one-liner to produce a list of HEX color codes that read like (supposedly) valid English words
$ grep -P "^[ABCDEFabcdefOoIi]{6,6}$" /usr/share/dict/words | tr 'OoIi' '0011' | tr '[:lower:]' '[:upper:]' | awk '{print "#" $0}'
#ACAD1A
#B0BB1E
#DEBB1E
#AB1DED
#ACAC1A
#ACCEDE
#AC1D1C
#BAB1ED
#BA0BAB
@bitsmanent
bitsmanent / react-native-sprite-sheets.js
Last active September 25, 2021 17:18
Simple sprite sheets for React Native
import React from "react";
import {ImageBackground} from "react-native";
export function Sprite(props) {
const [w, h] = [props.geometry.width, props.geometry.height];
const r = Math.min(w / (props.width / props.cols), h / (props.height / props.rows));
return (
<ImageBackground
source={props.source}
@lmillucci
lmillucci / greenpass.js
Created June 29, 2021 12:08
Simple green pass decoder in JavaScript
/**
* Simple green pass decoder inspired by https://git.gir.st/greenpass.git/blob_plain/master:/greenpass.py
*
* 2021 Lorenzo Millucci
*
* Before usage install following dependecies `npm install base45 cbor jpeg-js jsqr pako`
*/
const base45 = require('base45');
const cbor = require('cbor');
@zazapeta
zazapeta / auth.js
Created November 23, 2019 10:43
Password hashing/verifying in node.js using 'pbkdf2'
const crypto = require("crypto");
// larger numbers mean better security
const config = {
// size of the generated hash
hashBytes: 32,
// larger salt means hashed passwords are more resistant to rainbow table, but
// you get diminishing returns pretty fast
saltBytes: 16,
// more iterations means an attacker has to take longer to brute force an
@JoeyBurzynski
JoeyBurzynski / 55-bytes-of-css.md
Last active July 20, 2024 05:29
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@Jessidhia
Jessidhia / react-scheduler.md
Last active June 11, 2024 10:48
Implementation notes on react's scheduling model as of (shortly before) 16.8.0

Implementation notes on react's scheduling model as of (shortly before) 16.8.0

While the public API intended for users to use is the scheduler package, the reconciler currently does not use scheduler's priority classes internally.

ReactFiberScheduler has its own internal "mini-scheduler" that uses the scheduler package indirectly for its deadline-capable scheduleCallback.

This is kind of a documentation of implementation details that I suppose will be gone by the end of the year, but what can you do.

@RabaDabaDoba
RabaDabaDoba / ANSI-color-codes.h
Last active July 27, 2024 14:58 — forked from iamnewton/bash-colors.md
The entire table of ANSI color codes working in C!
/*
* This is free and unencumbered software released into the public domain.
*
* For more information, please refer to <https://unlicense.org>
*/
//Regular text
#define BLK "\e[0;30m"
#define RED "\e[0;31m"
#define GRN "\e[0;32m"
@agapas
agapas / dirReduc.js
Created December 2, 2017 14:20
trivia (javascript) - dirReduc
/*
Once upon a time, on a way through the old wild west,…
… a man was given directions to go from one point to another. The directions were "NORTH", "SOUTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "EAST" too. Going to one direction and coming back the opposite direction is a needless effort. Since this is the wild west, with dreadfull weather and not much water, it's important to save yourself some energy, otherwise you might die of thirst!
How I crossed the desert the smart way.
The directions given to the man are, for example, the following:
["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"].
You can immediatly see that going "NORTH" and then "SOUTH" is not reasonable, better stay to the same place!
So the task is to give to the man a simplified version of the plan.
A better plan in this case is simply:
["WEST"]
@palopezv
palopezv / dwm_config_pulseaudio.h
Last active July 24, 2024 02:46 — forked from neuro-sys/dwmconfig.h
dwm volume control with hardware multimedia keys (pipewire, pulseaudio, amixer and light as an extra)
/**
* dwmconfig.h
* Hardware multimedia keys
*/
/* Somewhere at the beginning of config.h include: */
/*
You obviously need the X11 development packages installed, X11proto in particular, but
here is the location of the keysyms header upstream copy if you can't bother
using the contents of your own hard drive. ;-P