Skip to content

Instantly share code, notes, and snippets.

@Lightnet
Lightnet / GunKeys.mjs
Created March 26, 2022 20:21
vue 3.x gun plugin
export const GunInjectKey = Symbol();
@Lightnet
Lightnet / README.md
Last active March 24, 2022 22:18
Vue 3 Event Bus Plugin
@Lightnet
Lightnet / EntityTransformControl.vue
Last active March 23, 2022 22:25
Vuejs TransformControls troisjs
<script setup>
/*
LICENSE: MIT
Created by: Lightnet
*/
// https://sbcode.net/threejs/transform-controls/
// https://github.com/mrdoob/three.js/blob/master/examples/misc_controls_transform.html
// https://threejs.org/examples/#misc_controls_transform
import { TransformControls } from 'three/examples/jsm/controls/TransformControls';
@Lightnet
Lightnet / README.md
Last active March 10, 2022 00:04
react vite express testing logging for file path open link.

Creating logging for React.js.

Note that nodejs and broswer is different one is file path and other is browser path.

Notice that broswer js is tricky depend on the build which is webpack bundle.js if there change in format it goes back to bundle.js instead of src path.

let e = new Error(args);
let stack = String(e.stack)
// fail, go to bundle.js url
@Lightnet
Lightnet / README.md
Last active March 8, 2022 19:42
use Axios refresh Token API to reduce code repeat

use search engine to learn hook and axios for clean up and reuse.

Worked on refine the code to deal with the user interacting when type when render components.

Create the init instance when it mount.

Added isLoading to make sure the axios instance. One reason is that useEffect mount on when user doing get url on render to get data.

Watch variables and mount interceptors that check for the token expire. If events it will change in interceptors and clean up.

@Lightnet
Lightnet / AuthProvider.jsx
Created March 7, 2022 22:43
token setup idea and prototype for one token and other refresh token. reactjs
/*
LICENSE: MIT
Created by: Lightnet
*/
import React,{ createContext, useState, useMemo, useContext, useEffect } from "react";
//import useFetch from "../hook/useFetch.mjs";
import {
parseJwt
//, isEmpty
@Lightnet
Lightnet / AceEditor.jsx
Last active March 6, 2022 21:36
Reactjs AceEditor.jsx simple ssr check
import React, { useEffect, useState } from "react";
export default function AceEditor(props){
const [Ace, SetAce] = useState(null);
useEffect( async()=>{
if (typeof window !== 'undefined') {//server ssr
const ReactAce = await import("react-ace"); //load in order
//await import("ace-builds/src-noconflict/mode-java"); //load in order
@Lightnet
Lightnet / EventLog.js
Created February 22, 2022 19:14
React Custom Event Context
//listen to event context
import React,{ useEffect, useState } from "react";
import { useEvent } from "./EventProvider.js";
export default function EventLog(){
const [log, setLog] = useState("");
const {event} = useEvent();
@Lightnet
Lightnet / reactContext.js
Created November 20, 2021 21:42
react Context Provider example
import { createContext, useContext, useMemo, useState } from "react";
// create content variable for store data
export const ForumContext = createContext();
// check Provider root level top
export function useForum(){
const context = useContext(ForumContext);
if (!context) {
throw new Error(`useForum must be used within a UserContext`)
@Lightnet
Lightnet / useEvent.js
Created November 15, 2021 07:16
found simple useEvent for react
//https://atomizedobjects.com/blog/javascript/develop-2d-javascript-games-html5-react/
import { useEffect } from 'react';
export default function useEvent(event, handler) {
useEffect(() => {
// initiate the event handler
window.addEventListener(event, handler);