Skip to content

Instantly share code, notes, and snippets.

View assertnotnull's full-sized avatar
🏠
Working from home

Patrice Gauthier assertnotnull

🏠
Working from home
View GitHub Profile
@assertnotnull
assertnotnull / proof.ts
Created October 19, 2022 17:57
mapAsync
import { PerformanceObserver, performance } from 'perf_hooks';
import R from "ramda";
const perfObserver = new PerformanceObserver((items) => {
items.getEntries().forEach((entry) => {
console.log(`${entry.name}: ${entry.duration}}`)
})
})
perfObserver.observe({entryTypes: ["measure"]})
@assertnotnull
assertnotnull / promiseMap.ts
Last active October 25, 2021 17:43
Map promises
import R from 'ramda'
export async function mapAsync<Type, ReturnedType>(
promiseFunc: (value: Type) => Promise<ReturnedType>,
values: Type[],
chunk = 3
) {
const processChunk = processWithFunction<Type, ReturnedType>(promiseFunc)
const chunks = R.splitEvery(chunk, values)
return R.flatten(await R.reduce(processChunk, Promise.resolve([]), chunks))
@assertnotnull
assertnotnull / asyncstore.ts
Created September 24, 2020 02:39
reusable asyncstore
import { AsyncLocalStorage } from 'async_hooks';
const context = new AsyncLocalStorage;
export function getStore() {
return context;
}
export function run(cb) {
@assertnotnull
assertnotnull / main.tf
Created April 24, 2020 20:05
Use commit hash for file in s3 in terraform
locals {
file_path = "${var.path}/${var.file_name}"
commit_hash = data.external.commit_hash.result.commit
}
data "external" "commit_hash" {
program = ["echo", "{ \"commit\" : \"$(git rev-parse HEAD)\"}"]
}
resource "null_resource" "upload_zip_to_s3" {
triggers = {
zip_file_changed = filebase64sha256(local.file_path) // handle update latest version case
@assertnotnull
assertnotnull / dark.css
Created October 9, 2019 17:43
Dark mode CSS
@media (prefers-color-scheme: dark) {
body {
background-color: #444;
color: #e4e4e4;
}
a {
color: #e39777;
}
img {
filter: grayscale(30%);
@assertnotnull
assertnotnull / README.md
Created June 20, 2019 19:09
How to add ability to manage all sub folders git
@assertnotnull
assertnotnull / launch.json
Created May 16, 2019 20:26
For node 8 jest >23
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "jest run current file",
"request": "launch",
@assertnotnull
assertnotnull / .profile
Created May 16, 2019 13:08
Set dockerhost as env vars
# add this to your .profile
export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)
@assertnotnull
assertnotnull / bookmark.js
Created August 14, 2018 13:41
browser offline html/js/css editor
data:text/html,<body%20oninput="i.srcdoc=h.value+'<style>'+c.value+'</style><script>'+j.value+'</script>'"><style>textarea,iframe{width:100%;height:50%}body{margin:0}textarea{width:33.33%;font-size:18}</style><textarea%20placeholder=HTML%20id=h></textarea><textarea%20placeholder=CSS%20id=c></textarea><textarea%20placeholder=JS%20id=j></textarea><iframe%20id=i>
@assertnotnull
assertnotnull / setup.rb
Created August 13, 2018 16:22
chef cert-bot sync with s3
execute 'apt-get-update' do
command 'apt-get update'
ignore_failure true
end
# on host install
package 'iptables-persistent' do
action :install
end