Skip to content

Instantly share code, notes, and snippets.

View baptistemanson's full-sized avatar
🌼
Blooming

Baptiste Manson baptistemanson

🌼
Blooming
View GitHub Profile
const getGroupsById = (state, ids) => ids.map(id => state.groups[id])
const getUsersWithGroupsById = (state, ids) => ids.map(id => ({...state.users[id], groups: getGroupsById(state.users[id].groups)}))
@baptistemanson
baptistemanson / parallel.js
Created June 29, 2018 07:16
Node can use several threads, even if you only write JS
const fs = require("fs");
const util = require("util");
const readFile = util.promisify(fs.readFile);
async function long() {
const content = await readFile("./dummy1000000.csv", "utf-8");
content.split(/\n/);
}
const arr = [];
import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";
const Child = ({ onClick }) => <button onClick={onClick}>Click me</button>;
class Parent extends Component {
field = "hello";
handleClick = e => {
@baptistemanson
baptistemanson / night-day.jsx
Created July 17, 2018 01:27
changing component with time
// css is
// .day {color: black; background-color:white}
// .night {color: white; background-color:blue}
const DivChanging = ({ text }) => {
if (new Date().getHours() > 12) {
return <div class="night">{text}</div>;
} else {
return <div class="day">{text}</div>;
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://shone.com/anorak.json",
"title": "Anorak",
"description": "Portable Realtime Maritime Navigational Data Protocol",
"oneOf": [
{ "$ref": "#subscribeMessage" },
{ "$ref": "#unsubscribeMessage" },
{ "$ref": "#getMessage" },
{ "$ref": "#deltaMessage" },
async function scrapeProduct (url) {
// the same code as you have ...
return {srcText, price, title};
}
async function main() {
const results = await scrapeProduct("...");
// here you can do something with results = {srcText, price, title};
@baptistemanson
baptistemanson / gist:b2e1dd24022b493511203a217a215c39
Last active July 9, 2020 17:45
How many collision can I test in JS per frame.js
function isInside(pos, rect) {
return (
pos[0] > rect[0] && pos[1] > rect[1] && pos[0] < rect[2] && pos[1] < rect[2]
);
}
const rect1 = new Uint16Array([10, 10, 100, 1000]);
const rect2 = new Uint16Array([0, 0, 10, 10]);
const pos1 = new Uint16Array([250, 50]);
const pos2 = new Uint16Array([20, 20]);
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Ok(())`,
right: `Err(ERROR_DEVICE_LOST)`', C:\Users\Baptiste\.cargo\git\checkouts\gfx-e86e7f3ebdbc4218\0244e34\src\backend\vulkan\src\lib.rs:1476:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `1`,
right: `0`: Allocator dropped before all sets were deallocated', C:\Users\Baptiste\.cargo\git\checkouts\gpu-descriptor-a05b99db0270c787\df74fd8\gpu-descriptor\src\allocator.rs:117:9
stack backtrace:
0: 0x7ff7e7edea0e - std::backtrace_rs::backtrace::dbghelp::trace
at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca\/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:108
@baptistemanson
baptistemanson / struct.js
Created February 10, 2021 20:37
demo hashmap to structs
const fs = require("fs");
function dateCompress(d) {
return d.replace(/\.\d{3}\+\d{2}:\d{2}$/g, "Z");
}
function getSize(d) {
return Math.ceil(d.length / 1024).toLocaleString() + "kB";
}
const DIM = 5;
/**
* -1-DIM -DIM +1-DIM
* -1 i +1
* -1+DIM +DIM +1+DIM
*/
const _compute = (m, out) => {
for (let x = 1; x < DIM; x++) {
for (let y = 1; y < DIM; y++) {