Skip to content

Instantly share code, notes, and snippets.

@fitsum
fitsum / if(array.indexOf(someObj) === -1) {add} else {next}
Last active April 26, 2024 05:02
check if obj exists in array then add if not
var source = [{name: "Fitsum", race: "blk"},{name: "Alice", race: "wht"},{name: "Jen", race: "wht"},{name: "Kim", race: "blk"},{name: "Lee", race: "asn"}],
target = [];
function userExists(name, idx, oldArr) {
return target.some(function(el) {
return el.name === name;
});
}
function addUser(name, idx, newArr) {
@maciekglowka
maciekglowka / three-to-mtl.js
Created January 2, 2022 15:21
Extracting material data for OBJ files exported from THREE.js
const url = 'https://URL-TO-YOUR-GLTF.gltf'
function imageToData (image) {
// heavily inspired by COLLADA Exporter ;)
let canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
canvas.width = image.width
canvas.height = image.height
ctx.drawImage(image, 0, 0)
const dataUrl = canvas.toDataURL('image/png')
@piyushgarg-dev
piyushgarg-dev / Dockerfile
Created October 21, 2023 10:00
Docker In One Shot
FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs
COPY package.json package.json
COPY package-lock.json package-lock.json
@alexxuss1996
alexxuss1996 / deepCopy.js
Created January 4, 2023 11:13
Fuction to create obj copy w/o ref
function deepCopy(obj) {
var copy;
// Handle three simple types, null, and undefined
if (obj == null || typeof obj != "object") {
return obj;
}
// Handle Date
@fire1ce
fire1ce / oh-my-zsh on openwrt or lede-project.md
Last active April 26, 2024 05:00
Install oh-my-zsh on openwrt/lede-project

Install oh-my-zsh on OpenWrt

Install Requirements Packages

opkg update && opkg install ca-certificates zsh curl git-http

Install oh-my-zsh

@felipewget
felipewget / Chaser Test
Created October 7, 2018 07:24
This is a test of ordenation and median by obj key.
/**
* Archive to test of ordination and median
*
*
* @author Felipe Oliveira <felipe@chatnizer.com> OR <felipe.wget@gmail.com>
* @version 0.1
*/
var objSamples = [
{
@Jeff-Russ
Jeff-Russ / time_elapsed.js
Created May 15, 2016 04:40
Construct a JS obj to determine time elapsed in ms
// TimeElapsed constructs an object for use in determining
// time elapsed in milliseconds
// constructor:
function TimeElapsed(){
var start, elapsed;
function getstamp(){ return (new Date().getTime());}
this.get = function(){
@gabrielqmatos
gabrielqmatos / findInObj.js
Created September 4, 2019 14:31
easy search and extract obj path searching into object
function getPath(obj, key) {
paths = []
function getPaths(obj, path) {
if (obj instanceof Object && !(obj instanceof Array)) {
for (var k in obj){
paths.push(path + "." + k)
getPaths(obj[k], path + "." + k)
}
}
@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>