Skip to content

Instantly share code, notes, and snippets.

@julienetie
julienetie / husky-pnpm-pre-commit-error-on-linux
Last active March 24, 2024 04:25
husky-pnpm-pre-commit-error-on-linux
See comments
@julienetie
julienetie / detect-browser.js
Last active April 5, 2024 12:47
Detect the operating system (os), browser and browser version without relying on depreciated ways.
const navigatorErrorMessage = 'Could not find `userAgent` or `userAgentData` window.navigator properties to set `os`, `browser` and `version`'
const removeExcessMozillaAndVersion = /^mozilla\/\d\.\d\W/
const browserPattern = /(\w+)\/(\d+\.\d+(?:\.\d+)?(?:\.\d+)?)/g
const engineAndVersionPattern = /^(ver|cri|gec)/
const userAgentData = window.navigator.userAgentData
const userAgent = window.navigator.userAgent
const unknown = 'Unknown'
const empty = ''
const brandList = ['chrome', 'opera', 'safari', 'edge', 'firefox']
.parent-selector {
background: lime;
> .child-selector {
color: crimson;
}
}
@julienetie
julienetie / comments.json
Last active March 30, 2023 14:34
Comments JSON
[
{
"id": "5a6ce86d2af929789500e7ca",
"author": "Edsger W. Dijkstra",
"quote": "The computing scientist’s main challenge is not to get confused by the complexities of his own making."
},
{
"id": "5a6ce86f2af929789500e7f3",
"author": "Edsger W. Dijkstra",
"quote": "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
import { pasteInto } from '../../anti-framework.js'
let n = 0
// The view callback prevents conditions and loops and operators at runtime.
const counterView = pasteInto('#root', ({ n }) => `
<button value="-">-</button>
<button value="+">+</button>
<span>${n}</span>
`)
@julienetie
julienetie / calculate-linear-regression.js
Created March 24, 2022 00:59
Linear Regression experiment
//const data = [1.5, 3.8, 6.7, 9.0, 11.2, 13.6, 16]
const data = [4, 4, 3, 5, 4, 3, 2, 2, 3, 4, 1, 1, 3]
const x = data.map((_, i) => i + 1)
const y = data
const xy = data.map((value, i) => (i + 1) * value)
const xPow2 = data.map((_, i) => (i + 1) ** 2)
//const sumOfX =data.reduce((acc, _, i) => acc + i
@julienetie
julienetie / format-ISO-8601-date.go
Created March 23, 2022 17:39
Format ISO 8601 date Golang
package maiimport (
"fmt"
"time"
)
func main() {
layout := "2006-01-02T15:04:05Z"
t, err := time.Parse(layout, "2022-01-21T05:53:19Z")
if err != nil {
const objectPath = {
/*
Creates an object-path and assigns the value.
- object - object - The object to create the path onto
- stringLocation - string - The object path as a string.
- value - * - The value to assign. */
assign (object, stringLocation, value) {
const locationList = stringLocation.split(dot)
const locationListLength = locationList.length
@julienetie
julienetie / object-class-regexp.js
Created May 16, 2021 14:35
Object class RegExp
const string = "[object Window]";
const pattern = /[^[object ](.*)[^\]]/g;
string.match(pattern);
@julienetie
julienetie / get-events.js
Last active May 16, 2021 12:03 — forked from galpx/getEvents.js
Gets a list of all events in the browser
const isEvent0 = prop => 0 === prop.indexOf('on');
const getEventNames0 = (obj) => {
const result = [];
for (let prop in obj) {
if (!isEvent0(prop)) continue;
prop = prop.substr(2), result.push(prop);
}
return result;
}