Skip to content

Instantly share code, notes, and snippets.

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

Elias Rhouzlane nestarz

🏠
Working from home
View GitHub Profile
@nestarz
nestarz / cross-source.js
Last active November 10, 2019 14:27
Top Level Domains Whois (November 11, 2019)
const fs = require("fs")
const missings = [];
fs.readFile('./tlds_by_tld.json', 'utf-8', (err, file1) => {
fs.readFile('./tld.json', 'utf-8', (err, file2) => {
fs.readFile('./myjsonfile.json', 'utf-8', (err, file3) => {
const tlds1 = JSON.parse(file1)
const tlds2 = JSON.parse(file2)
const tlds2_obj = tlds2.reduce((res, { Domain, ...tld }) => {
res[Domain.toUpperCase().replace('.', '')] = tld;
@nestarz
nestarz / issue.vue
Created November 11, 2019 23:54
issue
<template>
<div class="story">
<h1 v-refs:sequence>opt out the yellow pages</h1>
<p
v-refs:sequence
>Before Internet, one mean to contact people in different places of the world was using the phone.</p>
<p v-refs:sequence>Each individuals were connected to each others by copper cables.</p>
<img
src="https://www.thisiscolossal.com/wp-content/uploads/2014/09/tower-1.jpg"
v-refs:sequence
@nestarz
nestarz / editable.js
Created November 19, 2019 19:57
Editable Vue Code Component with Syntax Highlight using Prism.js (global)
import { computed, ref, createElement as h } from "/vue.js";
export default {
props: {
lang: { type: String, default: "js" },
content: { type: String, default: "your code..." }
},
setup(props, { emit, refs }) {
const content = ref(props.content);
const highlighted = computed(() =>
@nestarz
nestarz / poster.js
Last active November 20, 2019 15:49
Poster holder
import { ref, onMounted, h, onUnmounted } from "../vue.esm-browser.js";
const getVmax = () =>
window.innerHeight < window.innerWidth
? window.innerHeight
: window.innerWidth;
export default {
props: {
width: { type: Number, default: "210mm" },
@nestarz
nestarz / client.js
Last active March 1, 2020 14:20
Websockets (socket.io) + WebRTC
let log_verbose = 0;
export const log = (...args) => {
if (log_verbose) {
const div = document.createElement("div");
div.innerText = args.join(", ");
document.body.appendChild(div);
console.log(...args);
}
};
@nestarz
nestarz / webgpu-shader-test.html
Last active March 8, 2020 16:06
WebGPU Shader test (time-based)
<style>
html,
body {
height: 100%;
margin: 0;
}
</style>
<script type="x-shader/x-vertex" id="vertex-shader">
#version 450
@nestarz
nestarz / Random.onUnitSphere.js
Created April 2, 2020 23:22
Returns a random point on the surface of a sphere with radius 1.
// Fastest
// Marsaglia (1972)
// https://stackoverflow.com/a/5408344
const randomOnUnitSphere = N => {
const vectors = new Float32Array(N * 3);
for (let i = 0; i < N; i++) {
let x, y, z, norm;
while (true) {
x = 0.5 - Math.random();
@nestarz
nestarz / portAvailable.js
Created May 23, 2020 11:01
Check Port Availability
import net from "net";
export default (port) =>
new Promise((resolve) => {
const remove = (client) => {
client.removeAllListeners("connect");
client.removeAllListeners("error");
client.end();
client.destroy();
client.unref();
@nestarz
nestarz / classs-with-string.js
Last active May 26, 2020 23:49
Conditional Class using Object Representation
export const classs = (...args) =>
args
.flatMap((object) =>
object
? typeof object === "string"
? object
: Object.entries(object).reduce(
(str, [name, bool]) => (bool && name ? [...str, name] : str),
[]
)
@nestarz
nestarz / Tabs.jsx
Last active May 24, 2020 20:12
Tabs using React
import React, { useState } from "react";
const classs = (object) =>
Object.entries(object).reduce(
(str, [name, bool]) => `${str}${bool ? ` ${name}` : ""}`,
""
);
const Tabs = ({ children }) => {
const [active, setActive] = useState(0);