Skip to content

Instantly share code, notes, and snippets.

View dmail's full-sized avatar
🏸

Damien Maillard dmail

🏸
  • Datadog
  • Antibes
View GitHub Profile
@dmail
dmail / magic_source.js
Created March 1, 2022 14:29
Magic source
import { urlToFileSystemPath } from "@jsenv/filesystem"
import { require } from "@jsenv/core/src/internal/require.js"
export const createMagicSource = ({ url, content, sourcemap }) => {
if (content === undefined) {
throw new Error("content missing")
}
const filename = urlToFileSystemPath(url)
const {
@dmail
dmail / animate.js
Created September 16, 2020 17:01
Animation in javascript
document.querySelector('button').onclick = () => {
const scrollStart = document.querySelector(".menu-wrapper").scrollLeft
const scrollEnd = scrollStart + menuWrapperSize
startJavaScriptAnimation({
duration: 300,
onProgress: ({ progress }) => {
document.querySelector(".menu-wrapper").scrollLeft =
scrollStart + (scrollEnd - scrollStart) * progress
},
})
@dmail
dmail / createSignal.js
Created September 14, 2020 08:16
react store stuff
export const createSignal = () => {
let listeners = []
const listen = (callback) => {
let removed = false
listeners = [...listeners, callback]
return () => {
if (removed) return
removed = true
const listenersWithoutCallback = []
@dmail
dmail / index.html
Created July 7, 2020 12:52
redux stuff
<html>
<head>
<title>Redux stuff</title>
</head>
<body>
<main>
<iframe src="./without-redux.html"></iframe>
<iframe src="./with-redux.html"></iframe>
</main>
<style>
@dmail
dmail / debounce.js
Created July 6, 2020 08:10
debounce incoming requests ensuring max X requests are handled at the same time and debouncing gradually in batches
const debounce = (
fn,
{ debounceInterval = 50, maxConcurrentRequests = 15, unstackCount = 10 } = {},
) => {
let queue = []
let pendingCount = 0
const debouncedFn = async (request) => {
let entry
const promise = new Promise((resolve, reject) => {
entry = { request, resolve, reject }
@dmail
dmail / composeProps.js
Created June 2, 2020 09:06
make props overridable by composition. In the end might be better to make this explicit otherwise it becomes hard to follow.
const composeProps = (leftProps, rightProps) => {
const composedProps = { ...rightProps }
Object.keys(leftProps).forEach((key) => {
const leftValue = leftProps[key]
if (key in rightProps) {
const rightValue = rightProps[key]
composedProps[key] = composeProp(leftValue, rightValue)
} else {
composedProps[key] = leftValue
@dmail
dmail / code+nowrap.md
Last active April 10, 2020 09:44
Table header wrapping test

File by file impact

File Diff branch-name branch-with-a-long-name Event
@dmail
dmail / listPullRequestForBranch.js
Created August 20, 2019 09:11
listPullRequestForBranch
// https://developer.github.com/v3/pulls/#list-pull-requests
const fetch = require("node-fetch")
const listPullRequestForBranch = async ({ token, repoOwner, repoName, head }) => {
try {
const href = `https://api.github.com/repos/${repoOwner}/${repoName}/pulls?head=${encodeURIComponent(
head,
)}`
const response = await fetch(href, {
headers: {
@dmail
dmail / commentGithubPullRequest.js
Created August 20, 2019 09:11
commentGithubPullRequest
// https://developer.github.com/v3/issues/comments/#create-a-comment
// https://developer.github.com/v3/issues/comments/#edit-a-comment
const fetch = require("node-fetch")
const commentGithubPullRequest = async ({
token,
repoOwner,
repoName,
issueNumber,
commentBody,
@dmail
dmail / generate-lighthouse-report.js
Created August 19, 2019 15:36
generate lighthouse report
const lighthouse = require("lighthouse")
const chromeLauncher = require("chrome-launcher")
const launchChromeAndRunLighthouse = async ({ url, opts, config = null }) => {
const chrome = await chromeLauncher.launch({ chromeFlags: opts.chromeFlags })
opts.port = chrome.port
const results = await lighthouse(url, opts, config)
// use results.lhr for the JS-consumeable output
// https://github.com/GoogleChrome/lighthouse/blob/master/types/lhr.d.ts
// use results.report for the HTML/JSON/CSV output as a string