Skip to content

Instantly share code, notes, and snippets.

View elundmark's full-sized avatar
💭
I may be slow to respond.

elundmark

💭
I may be slow to respond.
View GitHub Profile

Saved for my personal reference, all content belongs to codetheory.in

Controlling the Frame Rate with requestAnimationFrame

Limiting the frame rate while using requestAnimationFrame can be a common want especially when coding Games where you want your animations and mechanics to not exceed a particular mark of frames per second. Let’s go through 2 ways of doing it.

Quick and Easy Way

Using setTimeout inside the rAF method is an easy way.

@elundmark
elundmark / youtube_url_to_xspf.js
Last active October 23, 2023 15:26
Youtube Video Url to XSPF file Stream
var ytPage = process.argv.length === 3 ? process.argv[2] : null,
idPatt = /^.*(?:(?:youtu.be\/)|(?:v\/)|(?:\/u\/\w\/)|(?:embed\/)|(?:watch\?))\??v?=?([^#\&\?]*).*/i,
idMatch = ytPage ? ytPage.match(idPatt) : null,
id = idMatch && idMatch.length === 2 && idMatch[1] && idMatch[1].length === 11
? idMatch[1] : null,
fmt = [ 18, 22, 35, 6, 5 ],
ytdl;
if (!id) exitError();

Problem:

Running a .desktop file from anything else than a launcher or a filemanager doesn't work, even if called via xdg-open (bug)

Solution:

Create a python file and call it, passing any .desktop file path.

#!/usr/bin/python

Setup fake HTTPS SSL certificate on Linux

  • Good links to open and read first.
  • Install curl openssl libnss3-tools
  • Open terminal (Become root first ! su -l)
mkdir /etc/ssl/self-signed && cd /etc/ssl/self-signed
openssl genrsa -des3 -out server.key 1024
openssl rsa -in server.key -out server.key.insecure
@elundmark
elundmark / generate_killer_sudoku_cheatsheet.py
Last active May 11, 2023 11:42
Generate cheatsheet for killer sudoku
#!/usr/bin/python3
"""
Generate cheatsheet of possible combinations of numbers in killer sudoku cells
"""
from itertools import chain, combinations
import sys
def powerset(iterable):
"""https://stackoverflow.com/questions/464864/"""
s = list(iterable) # allows duplicate elements
@elundmark
elundmark / make_m3u_youtube_playlist.sh
Last active April 9, 2023 11:40
Make m3u playlist of a Youtube Playlist (youtube-dl & jq must be installed)
#!/usr/bin/env bash
# $ ./make_m3u_youtube_playlist.sh [-d OUTPUT-DIR] URL [URL ...]
if ! which jq &>/dev/null || ! which youtube-dl &>/dev/null; then
echo "'youtube-dl' and 'jq' must be installed in \$PATH, exiting." 1>&2
exit 1
fi
declare log_file="$HOME/.make_m3u_youtube_playlist.log"
@elundmark
elundmark / test_stdin.sh
Last active October 13, 2022 16:11
Using the test command with STDIN
#!/usr/bin/env bash
set +H
# Using STDIN, check LINES of FILES and use the test command to filter by EXPRESSION
# Supports all EXPRESSIONS that test does.
# fn | test_stdin -f \! -d -L -s \! -ot FILEARG
# Use '!' to negate results. -ef, -ot, -nt will be read as "LINE -nt FILEARG"
if [[ $# -eq 0 ]] ; then
# An omitted EXPRESSION defaults to false (see manpage for test)
@elundmark
elundmark / secure_bash_passwords.sh
Created July 18, 2012 12:15
Store and use secure passwords in bash
#!/bin/bash
# Mixing in python with bash we can easily retrieve our passwords securely in our shell scripts.
# Read this first: https://live.gnome.org/GnomeKeyring/SecurityPhilosophy
# Make sure your distro has gnome-keyring-daemon installed and running at login,
# as well as python-keyring installed (sudo apt-get install python-keyring)
##
# Follow these steps to see what it does. Verify by looking in Seahorse for your password.
##
@elundmark
elundmark / vsleep
Last active August 12, 2022 05:25
Verbose Sleep - echo the progress to stderr
#!/usr/bin/env bash
get_ms () {
date +'%s%N' | grep -oP '^[0-9]{13}'
}
show_usage () {
# *******************************************************************
read -d '' help_text <<- EOF
vsleep - verbose sleep
@elundmark
elundmark / rain.sh
Created July 27, 2019 12:18
Rainbows!
#!/usr/bin/env bash
set -e
repeat_char () {
printf '%0*d' "$2" 0 | sed 's/0/'"$1"'/g'
return 0
}
if ! command -v lolcat; then