Skip to content

Instantly share code, notes, and snippets.

View caracal7's full-sized avatar

Dmitrii Vasilev caracal7

  • This planet
View GitHub Profile
@AaronFlower
AaronFlower / proxy-observable.js
Created November 30, 2017 15:47
javascript Proxy Reflect
/**
* Use Proxy to implement observable
*/
function observable (obj, onchange) {
return new Proxy(obj, {
set (target, key, value) {
Reflect.set(target, key, value)
onchange(key, value)
},
delete (target, key) {
@davidrleonard
davidrleonard / from-now.js
Last active February 18, 2024 11:23
moment.fromNow() implemented in vanilla JavaScript as a simple, standalone function. Runs in the browser. No dependencies required.
/**
* Implements all the behaviors of moment.fromNow(). Pass a
* valid JavaScript Date object and the method will return the
* time that has passed since that date in a human-readable
* format. Passes the moment test suite for `fromNow()`.
* See: https://momentjs.com/docs/#/displaying/fromnow/
*
* @example
*
* var pastDate = new Date('2017-10-01T02:30');
@TheAlchemist64
TheAlchemist64 / ecs.js
Created October 8, 2017 21:11
A single file Javascript Entity Component System
/*
A Javascript port of the RDBMS-inspired Entity Component System found here:
https://github.com/adamgit/Entity-System-RDBMS-Inspired-Java/blob/master/EntitySystemJava/
src/com/wikidot/entitysystems/rdbmswithcodeinsystems/EntityManager.java
*/
export default class EntityManager {
constructor(){
this.lowestUnassignedID = 1;
@atinux
atinux / async-foreach.js
Last active April 2, 2025 11:34
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@markus-willems
markus-willems / tabs.js
Created September 27, 2017 13:03
Tabs Component
import React from "react";
import { render } from "react-dom";
const App = () => (
<Tabs>
<TabList>
<Tab>Tab 1</Tab>
<Tab>Tab 2</Tab>
<Tab>Tab 3</Tab>
</TabList>
@LeaVerou
LeaVerou / log-traps.js
Last active January 28, 2018 12:22
Log all proxy traps
function createLoggedProxy(obj) {
var traps = {};
for (let trap of Object.getOwnPropertyNames(Reflect)) {
traps[trap] = (...args) => {
console.log(trap, ...args.slice(0, -1)); // Last arg is always the proxy, no need to log it
return Reflect[trap](...args);
}
}
@s-melnikov
s-melnikov / nested_sets.js
Created August 9, 2017 06:31
Nested sets
var data = [
{
title: "Одежда",
left: 1,
right: 22
},
{
title: "Мужская",
left: 2,
right: 9
@audinue
audinue / README.md
Last active January 26, 2018 22:08
Fun

Fun

Fun is a javascript entity-component-system game framework.

Entities is represented by a plain javascript object.

// The player entity
const player = {
}
@nicolasdelfino
nicolasdelfino / astar.js
Last active February 3, 2018 13:38
AStar algorithm
export let AStar = (_grid, start, end, units, currentSelectionID) => {
// Reset score of cells
_grid.resetCells()
// pass tanks to grid and make them obstacles
_grid.makeObstaclesOfUnitsWithHigherMass(units[currentSelectionID], units, currentSelectionID)
// Add possible cell neighbors, pass unit A* style
let aStarStyle = units[currentSelectionID].aStarStyle
_grid.addCellNeighbors(aStarStyle)
let openSet = []
let closedSet = []
@dmnsgn
dmnsgn / WebGL-WebGPU-frameworks-libraries.md
Last active May 6, 2025 19:29
A collection of WebGL and WebGPU frameworks and libraries

A non-exhaustive list of WebGL and WebGPU frameworks and libraries. It is mostly for learning purposes as some of the libraries listed are wip/outdated/not maintained anymore.

Engines and libraries ⚙️

Name Stars Last Commit Description
three.js ![GitHub