Skip to content

Instantly share code, notes, and snippets.

View bastienrobert's full-sized avatar
🎲
728

Bastien Robert bastienrobert

🎲
728
View GitHub Profile
@bastienrobert
bastienrobert / detect-video-autoplay.js
Created April 5, 2023 09:01
Detect if video autoplay is allowed
const video = document.createElement("video")
video.setAttribute("muted", "")
video.setAttribute("playsInline", "")
video.src = "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAAs1tZGF0AAACrgYF//+q3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE0OCByMjYwMSBhMGNkN2QzIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAxNSAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTMgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MzoweDExMyBtZT1oZXggc3VibWU9NyBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0xIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MSA4eDhkY3Q9MSBjcW09MCBkZWFkem9uZT0yMSwxMSBmYXN0X3Bza2lwPTEgY2hyb21hX3FwX29mZnNldD0tMiB0aHJlYWRzPTEgbG9va2FoZWFkX3RocmVhZHM9MSBzbGljZWRfdGhyZWFkcz0wIG5yPTAgZGVjaW1hdGU9MSBpbnRlcmxhY2VkPTAgYmx1cmF5X2NvbXBhdD0wIGNvbnN0cmFpbmVkX2ludHJhPTAgYmZyYW1lcz0zIGJfcHlyYW1pZD0yIGJfYWRhcHQ9MSBiX2JpYXM9MCBkaXJlY3Q9MSB3ZWlnaHRiPTEgb3Blbl9nb3A9MCB3ZWlnaHRwPTIga2V5aW50PTI1MCBrZXlpbnRfbWluPTEwIHNjZW5lY3V0PTQwIGludHJhX3JlZnJlc2g9MCByY19sb29rYWhlYWQ9NDAgcmM9Y
@bastienrobert
bastienrobert / elo.ts
Last active March 5, 2022 00:29
Simple implementation of Elo rating system in typescript
// https://en.wikipedia.org/wiki/Elo_rating_system
const K = 32
export enum EloStatus {
LOOSE = 0,
DRAW = 0.5,
WIN = 1
}
@bastienrobert
bastienrobert / BrowserDeviceInfo.js
Last active August 15, 2021 09:23 — forked from TrevorJTClarke/BrowserDeviceInfo.js
List of browsers and devices for use in testing. Useful after Chrome removes HiDPI & MDPI laptop sizes in emulated devices.
var devices = [
{ name: 'Desktop - Huge', width: 2880, height: 1800, ratio: 2, type: 'desktop' },
{ name: 'Desktop - Extra Large', width: 1920, height: 1080, ratio: 1, type: 'desktop' },
{ name: 'Desktop - Large', width: 1440, height: 900, ratio: 1, type: 'desktop' },
{ name: 'Desktop - HiDPI', width: 1366, height: 768, ratio: 1, type: 'desktop' },
{ name: 'Desktop - MDPI', width: 1280, height: 800, ratio: 1, type: 'desktop' },
{ name: 'Laptop with HiDPI screen', width: 1440, height: 900, ratio: 2, type: 'desktop' },
{ name: 'Laptop with MDPI screen', width: 1280, height: 800, ratio: 1, type: 'desktop' },
{ name: 'Laptop with touch', width: 1280, height: 950, ratio: 1, type: 'desktop' },
{ name: 'Tablet - Portrait', width: 768, height: 1024, ratio: 1, type: 'tablet' },
@bastienrobert
bastienrobert / OrbitControls.js
Last active March 11, 2021 17:10
Orbit Controls in THREEJS with ES6 modules
import * as THREE from 'three';
// Disable ESLINT for this page
/* eslint-disable */
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
@bastienrobert
bastienrobert / index.js
Created March 9, 2021 10:19
crawl array to any size +/- offset
function crawlArray(arr, cur, n) {
return ((cur + n) % arr.length + arr.length) % arr.length
}
@bastienrobert
bastienrobert / index.js
Created January 25, 2021 13:05
Shortest clamped distance
function shorterDirection(cur, next, max) {
const toRight = (next - cur + max) % max
const toLeft = (cur - next + max) % max
return toRight > toLeft ? -toLeft : toRight
}
@bastienrobert
bastienrobert / pngfolder2webp.js
Created May 20, 2020 09:50
convert folder full of PNG sprite into animated WEBP with alpha
const { exec } = require('child_process')
const fs = require('fs')
const path = require('path')
const args = process.argv.slice(2)
const FPS = 30
const FRAME_DURATION_MS = 1000 / FPS
if (!args[0]) console.log('please set a folder in params')
@bastienrobert
bastienrobert / regex
Last active April 24, 2020 13:29
List of usefull regex
Split URL params (eg. /foo/:bar)
/:[^\/]+/
@bastienrobert
bastienrobert / share-urls.md
Last active April 22, 2020 14:32 — forked from juliendargelos/share-urls.md
Share urls cheatsheet for social networks
@bastienrobert
bastienrobert / db.rake
Created April 21, 2020 12:34 — forked from ssaunier/db.rake
Rake task to back up heroku database and restore it locally.
namespace :db do
desc "Backs up heroku database and restores it locally."
task import_from_heroku: [ :environment, :create ] do
HEROKU_APP_NAME = nil # Change this if app name is not picked up by `heroku` git remote.
c = Rails.configuration.database_configuration[Rails.env]
heroku_app_flag = HEROKU_APP_NAME ? " --app #{HEROKU_APP_NAME}" : nil
Bundler.with_clean_env do
puts "[1/4] Capturing backup on Heroku"
`heroku pg:backups capture DATABASE_URL#{heroku_app_flag}`