Skip to content

Instantly share code, notes, and snippets.

Avatar
🎲
728

Bastien Robert bastienrobert

🎲
728
View GitHub Profile
@bastienrobert
bastienrobert / elo.ts
Last active Mar 5, 2022
Simple implementation of Elo rating system in typescript
View elo.ts
// https://en.wikipedia.org/wiki/Elo_rating_system
const K = 32
export enum EloStatus {
LOOSE = 0,
DRAW = 0.5,
WIN = 1
}
@bastienrobert
bastienrobert / export.js
Last active Aug 23, 2021
Export GitHub labels from web
View export.js
// paste this code inside the JS console
// use the output with import.js
function hex(x) {
return ('0' + parseInt(x).toString(16)).slice(-2)
}
function rgba2hex(rgba) {
rgba = rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(,\s*\d+\.*\d+)?\)$/)
return hex(rgba[1]) + hex(rgba[2]) + hex(rgba[3])
}
@bastienrobert
bastienrobert / BrowserDeviceInfo.js
Last active Aug 15, 2021 — 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.
View BrowserDeviceInfo.js
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 Mar 11, 2021
Orbit Controls in THREEJS with ES6 modules
View OrbitControls.js
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 Mar 9, 2021
crawl array to any size +/- offset
View index.js
function crawlArray(arr, cur, n) {
return ((cur + n) % arr.length + arr.length) % arr.length
}
@bastienrobert
bastienrobert / index.js
Created Jan 25, 2021
Shortest clamped distance
View index.js
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
convert folder full of PNG sprite into animated WEBP with alpha
View pngfolder2webp.js
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 Apr 24, 2020
List of usefull regex
View regex
Split URL params (eg. /foo/:bar)
/:[^\/]+/
@bastienrobert
bastienrobert / db.rake
Created Apr 21, 2020 — forked from ssaunier/db.rake
Rake task to back up heroku database and restore it locally.
View db.rake
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}`