Skip to content

Instantly share code, notes, and snippets.

@jniac
jniac / anyDicesComparison.js
Last active June 21, 2020 20:38
roll some dices
D = n => Math.ceil(n * Math.random())
run = ({ name = 'run', d1, d2, n = 100000 } = {}) => {
result = {
win: 0,
loose: 0,
equals: 0,
}
@jniac
jniac / prune.js
Last active September 25, 2020 09:35
// https://gist.github.com/jniac/39eabea6b06a9be5be348c11447c249c
/**
* 'prune' will simplify any tree (target) by removing any 'autoKey'
* found by its inner value. eg:
*
* `prune({ text:{ en:'foo', fr:'toto' }}, 'en') // -> { text:'foo' }`
* `prune({ text:{ en:'foo', fr:'toto' }}, 'fr') // -> { text:'toto' }`
* @param {object} target
* @param {...string} autoKeys
*/
function ScreenScalar(props = { p1:1, p2:1 }) {
const compute = () => this.value = 1 - Object.values(props).reduce((r, v) => r * (1 - v), 1)
compute()
for (const key of Object.keys(props)) {
Object.defineProperty(this, key, {
get: () => props[key],
set: value => {
function deepClone(target) {
if (!target || typeof target !== 'object')
return target
const clone = Array.isArray(target) ? [] : {}
for (const [key, value] of Object.entries(target)) {
clone[key] = deepClone(value)
@jniac
jniac / walk.js
Last active June 11, 2020 12:58
walk.js
function* walk(object, currentPath = []) {
for (let [key, value] of Object.entries(object)) {
const path = [...currentPath, key]
yield [key, value, path]
if (value && typeof(value) === 'object')
yield* walk(value, path)
@jniac
jniac / extractValue.js
Last active September 24, 2020 13:48
super cool extractValue
// https://gist.github.com/jniac/35ec5237a0b06359ae37ba5802e12bef
const isNullOrUndefined = item => item === null || item === undefined
const isObject = item => !!(item && typeof item === 'object')
const clone = object => {
if (!isObject(object))
return object
@jniac
jniac / index.html
Created January 12, 2020 19:30
étienne ensaama ar demo 1
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>ar demo</title>
<script src='https://aframe.io/releases/0.9.2/aframe.min.js'></script>
<script src="https://raw.githack.com/jeromeetienne/AR.js/master/aframe/build/aframe-ar.min.js"></script>
<script src="https://raw.githack.com/donmccurdy/aframe-extras/master/dist/aframe-extras.loaders.min.js"></script>
<script>
@jniac
jniac / App.jsx
Last active January 10, 2020 08:56
moviedb dimi demo app
import React from 'react';
import { StyleSheet, Text, View, TextInput, KeyboardAvoidingView } from 'react-native';
import Button from './src/view/Button'
import Movies from './src/view/Movies'
const API_KEY = '870c92db52a5e74ad6c1b6b06b19cfb9'
const API_MOVIE_ENDPOINT = 'https://api.themoviedb.org/3/search/movie'
const getSearchUrl = (query, page = 1) => {
@jniac
jniac / App.tsx
Last active January 9, 2020 18:42
moviedb expo demo
import React from 'react';
import { StyleSheet, Text, View, TextInput, KeyboardAvoidingView } from 'react-native';
import Button from './src/view/Button'
import Movies from './src/view/Movies'
const API_KEY = '870c92db52a5e74ad6c1b6b06b19cfb9'
const API_MOVIE_ENDPOINT = 'https://api.themoviedb.org/3/search/movie'
const getSearchUrl = (query:string, page:number = 1) => {
@jniac
jniac / index-setup.js
Last active January 7, 2020 12:53
Minimal index.html setup script
let style = document.createElement('style');
style.innerHTML = $`
body, body > * {
box-sizing: border-box;
position: relative;
margin: 0;
display:flex;
flex-direction