Skip to content

Instantly share code, notes, and snippets.

@naivehhr
naivehhr / myGet.js
Created June 23, 2019 16:36
使用new Function 获取obj path 值
function fun(data, ...args) {
const res = JSON.stringify(data)
console.log(res)
const t = new Function('console.log("huhaoran")')
args.map(item => {
const tfun = new Function(`return ${res}.${item}`)
console.log(tfun())
})
}
@grantstandridge
grantstandridge / json_menus.html
Last active April 26, 2024 04:59
Select Menu Filter (from json obj)
<!--
DEMO FOR FILTERING JSON OBJECT & POPULATING DROPDOWN FIELDS.
===
jQuery not required for the parsing/filtering
jQuery only required for retrieving json object
===
by: Grant S
-->
<!DOCTYPE html>
@1polygon
1polygon / cookie.js
Created November 6, 2018 21:55
get/set cookies in js
@1polygon
1polygon / customscroll.js
Last active April 26, 2024 04:58
jquery simple custom scroll
var overScrollable = false, scrollSpeed = 150;
function updateScroll(state){
var overflow = state.e.parent().outerHeight() - state.e.prop('scrollHeight');
if(state.deltaY < 0){
state.scrollPos += scrollSpeed;
if(state.scrollPos > 0) state.scrollPos = 0;
state.e.css({"transform": "translateY(" + state.scrollPos + "px)"});
}
else if(overflow < 0) {
@1polygon
1polygon / file.js
Created December 4, 2018 13:41
crypto salted password
function setPassword(p){
salt = crypto.randomBytes(16).toString('hex');
hash = crypto.pbkdf2Sync(p, salt, 1000, 64, 'sha512').toString('hex');
}
function validPassword(p) {
return crypto.pbkdf2Sync(p, salt, 1000, 64, 'sha512').toString('hex') === hash;
}
@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