Skip to content

Instantly share code, notes, and snippets.

@1polygon
1polygon / tabs.html
Created December 11, 2018 16:53
jquery tabs
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery.js"></script>
<script src="tabs.js"></script>
<style>
nav {
border-bottom: 1px solid gray; cursor: default;
@1polygon
1polygon / ipc.js
Created September 12, 2020 14:26
node ipc
module.exports = function (proc) {
const timeout = 3000;
const events = new Map();
const rec_events = new Map();
var id = 0;
proc.on('message', (message) => {
if (message.type == 'request') {
var reply = { id: message.id, type: 'reply' }
@1polygon
1polygon / stopwatch.js
Created September 12, 2020 14:29
node stopwatch
const currentTime = () => process.hrtime()[0] * 1000 + process.hrtime()[1] / 1000000;
module.exports = class StopWatch {
constructor() {
this.startTime = 0;
this.pauseTime = 0;
this.running = false;
}
start() {
this.startTime = currentTime();
@1polygon
1polygon / glsl.js
Created November 21, 2022 19:33
vite plugin for importing glsl files
const fileRegex = /\.(frag|vert|fs|vs|glsl)$/
import fs from "fs";
import path from "path";
function processShader(src, id) {
const lines = src.split("\n");
let result = "";
for (const line of lines) {
if (line.startsWith("#include ")) {
const relativeFile = line.split(" ")[1];
@a-nooj
a-nooj / panda_jacobian.py
Last active April 26, 2024 04:55
Jacobian matrix for the Franka Emika Panda robot arm
import numpy as np
def get_tf_mat(i, dh):
a = dh[i][0]
d = dh[i][1]
alpha = dh[i][2]
theta = dh[i][3]
q = theta
@1polygon
1polygon / webgl-objloader.js
Created November 14, 2022 21:54
webgl convert obj to indexed mesh
import { Mesh } from "../mesh";
export async function loadOBJ(url) {
const res = await fetch(url);
if (res.status == 200) {
const text = await res.text();
const vertices = [];
const uv = [];
@muneebahmed26301
muneebahmed26301 / index.html
Created April 9, 2020 15:41
Three.js - Load .OBJ and .MTL file
<canvas id="c"></canvas>
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r105/three.min.js"></script>
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r105/js/controls/OrbitControls.js"></script>
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r105/js/loaders/LoaderSupport.js"></script>
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r105/js/loaders/OBJLoader2.js"></script>
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r105/js/loaders/MTLLoader.js"></script>
@gnilekaw
gnilekaw / reduce-object.js
Created August 25, 2016 20:16
reduce obj to array of keypaths and values
import { forEach as _forEach } from 'lodash/collection';
import {
isObject as _isObject,
isString as _isString,
isInteger as _isInteger
} from 'lodash/lang';
function _reduce(collection, keypath, accumulator) {
_forEach(collection, (value, key) => {
if (_isObject(value)) {
@davidchase
davidchase / README.md
Last active April 26, 2024 04:53
cookie obj from the folks at MDN, awesome!

Mozilla Developer Network

Cookies object

Forked from here

A complete cookies reader/writer framework with full unicode support.

This framework is released under the GNU Public License, version 3 or later.

@logicaroma
logicaroma / Element.js
Last active April 26, 2024 04:53
some extra utils on the Element obj
Element.prototype.hasClass = function (className) {
return new RegExp(' ' + className + ' ').test(' ' + this.className + ' ');
};
Element.prototype.addClass = function (className) {
if (!this.hasClass(className)) {
this.className += ' ' + className;
}
};