Skip to content

Instantly share code, notes, and snippets.

@ndesmic
ndesmic / match.js
Created October 16, 2024 22:38
File Matcher
import { Tokenizer } from "./tokenizer.js";
const textOutput = Deno.readTextFileSync("./output/doc.txt");
const textExpected = Deno.readTextFileSync("./expected/doc.txt");
const tokenizer = new Tokenizer([
{ matcher: /\{\{\{/, type: "regex-start" },
{ matcher: /\}\}\}/, type: "regex-end" },
{ matcher: /[a-zA-Z0-9\[\]\(\)\{\}\.\$\-:\!\\ \t]/, type: "string", valueExtractor: x => x }
]);
@ndesmic
ndesmic / deno-tools.js
Last active January 10, 2023 15:17
node tools
async function directoryToObject(dir, walkOpts){
const obj = {};
for await(const file of walk(dir, walkOpts)){
const path = relative(dir, file.path);
const split = path.split("/");
let currObj = obj;
for(let i = 0; i < split.length; i++){
const part = split[i];
@ndesmic
ndesmic / debug.js
Created September 29, 2018 06:04
Debug Scripts
function breakOn(selector){ //breaks on selector
var o = new MutationObserver(() => {
console.log("hello!");
debugger;
});
o.observe(document.querySelector(selector), {
childList: true
});
}
@ndesmic
ndesmic / killport.js
Last active September 29, 2018 06:06
killport
#! /usr/bin/env node
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const port = process.argv[2];
exec(`lsof -t -i :${port}`)
.then(result => exec(`kill -9 ${result.stdout}`))
.then(() => console.log(`Killed process using port ${port}`))
.catch(e => {
console.log(`Failed. Are you sure there was something using port ${port}?`);
@ndesmic
ndesmic / ReactAlert.js
Last active December 1, 2017 22:40 — forked from jfbrennan/ReactAlert.js
Alert UI component rebuilt to compare Riot vs Slim vs Polymer vs Vue vs React and more
import React from "react";
import ReactDOM from "react-dom";
class Alert extends React.Component {
constructor(props){
super();
this.state = {
dismissed : false,
transitionRef : null
};
(function() {
var scripts = document.getElementsByTagName( 'script' );
var thisScriptTag = scripts[ scripts.length - 1 ];
for (var index = scripts.length - 1; index >= 0; index--) {
if (scripts[index].src.indexOf("iframe.js") > -1) {
thisScriptTag = scripts[index];
break;
}
}
@ndesmic
ndesmic / stop-all-events.js
Last active October 20, 2016 19:25
DevTool Snippets
console.log("Event Apocalypse!");
var elements = Array.prototype.slice.call(document.querySelectorAll("*"));
elements.unshift(document);
var count = 0;
var elCount = 0;
elements.forEach(x => {
elCount++;
let events = getEventListeners(x);
for(let key in events){
let eventArray = events[key];