Skip to content

Instantly share code, notes, and snippets.

View magne4000's full-sized avatar

Joël Charles magne4000

View GitHub Profile
// WIP
function tryClone<T>(obj: T): T {
try {
return structuredClone(obj);
} catch (err) {
if (obj == null || typeof obj === "function") {
return obj;
}
if (typeof obj === "object") {
if (Array.isArray(obj)) {
{
"$schema": "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
"meta": {
"theme": "elegant"
},
"basics": {
"name": "Joël Charles",
"label": "Full Stack Freelance | Founder @ What's New Games",
"image": "https://getonmyhor.se/img/photo.jpg",
"email": "joel.charles91@gmail.com",
#!/bin/bash
settings () {
echo ""
echo "Configuration:"
echo ""
echo lidarr_eventtype "$lidarr_eventtype"
echo lidarr_artist_id "$lidarr_artist_id"
echo lidarr_artist_name "$lidarr_artist_name"

Those scripts can be run on the input page, directly from the devtool console.

Day 1: Report Repair

Part 1

v=document.querySelector('pre').innerHTML.split('\n').map(x => parseInt(x, 10)).filter(x => !isNaN(x));v.forEach(x=>{v.forEach(y=>{if(x+y===2020)r=x*y})});r

Part 2

v=document.querySelector('pre').innerHTML.split('\n').map(x => parseInt(x, 10)).filter(x => !isNaN(x));v.forEach(z=>{v.forEach(x=>{v.forEach(y=>{if(x+y+z===2020)r=x*y*z})})});r
@magne4000
magne4000 / perf-tests-bx.js
Last active May 28, 2019 14:07
Inject console FPS counter
(function(maxDurationParam){if(maxDurationParam===void 0){maxDurationParam=30}
var maxDuration=maxDurationParam*1000;var Animate=(function(){function Animate(){var _this=this;this.update=function(tickAt){if(tickAt-_this.lastInsertAt>=1000){_this.fps.push(_this.framesCount);_this.lastInsertAt=tickAt;_this.framesCount=0}
_this.framesCount+=1;if(tickAt-_this.startedAt<maxDuration){requestAnimationFrame(_this.update)}
else{_this.elem.dispatchEvent(new Event('finish'))}}}
Animate.prototype.start=function(startedAt){this.startedAt=startedAt;this.lastInsertAt=startedAt;this.framesCount=0;this.fps=[];this.elem=document.createElement('span');requestAnimationFrame(this.update)};Animate.prototype.waitFinish=function(){var _this=this;return new Promise(function(resolve){_this.elem.addEventListener('finish',resolve,!1)})};return Animate}());var average=function(list){return list.reduce(function(prev,curr){return prev+curr})/list.length};var anim=new Animate();anim.start(performance.now());console.log('FPS - test duration:
@magne4000
magne4000 / perf-tests-stats.js
Created May 23, 2019 12:25
Inject stats.js
(function(){var script=document.createElement('script');script.onload=function(){var stats=new Stats();document.body.appendChild(stats.dom);requestAnimationFrame(function loop(){stats.update();requestAnimationFrame(loop)});};script.src='https:////mrdoob.github.io/stats.js/build/stats.min.js';document.head.appendChild(script);})()
@magne4000
magne4000 / combineLatest.ts
Created April 18, 2018 16:45
RxJs combineLatest
const oa = Rx.Observable.from(['a0', 'a1', 'a2']);
const ob = Rx.Observable.from(['b0', 'b1', 'b2', 'b3']);
const oc = Rx.Observable.from(['c0', 'c1', 'c2', 'c3']);
const r1 = oa
.zip(Rx.Observable.interval(300), function(a, b) { return a; })
const r2 = ob
.zip(Rx.Observable.interval(440), function(a, b) { return a; })
@magne4000
magne4000 / as_dict_mixin.py
Last active June 8, 2016 07:49
SQLAlchemy Mixin adding as_dict() function. Supports inheritance
from itertools import chain
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Mixin(object):
def as_dict(self):
tables = [base.__table__ for base in self.__class__.__bases__ if base not in [Base, Mixin]]
tables.append(self.__table__)
return {c.name: getattr(self, c.name) for c in chain.from_iterable([x.columns for x in tables])}