Skip to content

Instantly share code, notes, and snippets.

@tluyben
tluyben / backets.js
Created December 9, 2022 12:02
match curly brackets
View backets.js
function getBrackets(str) {
// Initialize the stack to keep track of open braces
const stack = [];
// Initialize the result string
let result = "";
// Iterate over each character in the input string
for (let i = 0; i < str.length; i++) {
const char = str[i];
@tluyben
tluyben / chat.js
Created December 5, 2022 04:10
Simple chatbox in React with Material UI
View chat.js
import React from 'react';
import { useState } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
import Box from '@material-ui/core/Box';
import Divider from '@material-ui/core/Divider';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import List from '@material-ui/core/List';
@tluyben
tluyben / gist:95349907fe304c1ebc4bf4929b18d5c6
Created February 28, 2022 09:37
Diagnosing Wordpress infinite internal redirects (after installing theme / plugin / demo content)
View gist:95349907fe304c1ebc4bf4929b18d5c6
Line 1305 in wp-includes/pluggable.php you can find;
function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
that is probably what executes the redirect, so just add a
die($location);
to see if this is indeed the culprit.
@tluyben
tluyben / nostars.js
Created February 20, 2022 09:16
no stars for react-feedback component (the lazy way)
View nostars.js
setInterval(()=> {
document.getElementsByClassName('star-ratings')[0]?.style?.display = 'none';
document.getElementsByClassName('star')[4]?.parentElement?.parentElement?.click()
}, 100)
@tluyben
tluyben / Frame.jsx
Created February 4, 2022 16:51
React iframe rendering
View Frame.jsx
import React, { createRef } from "react";
import ReactDOM from "react-dom";
export default class Frame extends React.Component {
constructor(props) {
super(props)
this.ref = createRef()
}
render() {
return <iframe ref={this.ref}></iframe>
View aoc21_13.js
import { accessSync, promises as fs } from 'fs';
(async()=>{
const input = await fs.readFile("./interpretertests/aoc_21_13_input.txt", 'utf8')
const p = (grid) => {
for (let y = 0; y < grid.length; y++) {
console.log(grid[y].map(x=>x==0?'.':'#').join(''))
View aoc21_7.js
import { accessSync, promises as fs } from 'fs';
(async()=>{
const input = await fs.readFile("./interpretertests/aoc_21_7_input.txt", 'utf8')
const positions = input.split('\n')[0].split(',').map(Number)
const max = Math.max(...positions)
View aoc21_6.js
import { timeStamp } from 'console';
import { accessSync, promises as fs } from 'fs';
(async()=>{
const input = await fs.readFile("./interpretertests/aoc_21_6_input.txt", 'utf8')
const f = (days) => {
const timers = input.split(',').map(Number)
let days8 = timers.map(t=>[1, t])
View aoc21_2.js
import { accessSync, promises as fs } from 'fs';
(async()=>{
const input = await fs.readFile("./interpretertests/aoc_21_2_input.txt", 'utf8')
const result = input.split('\n').reduce((acc, line) => {
let [cmd, i] = line.split(' ')
i = parseInt(i)
switch(cmd) {
View aoc21_5.js
import { accessSync, promises as fs } from 'fs';
(async()=>{
const input = await fs.readFile("./interpretertests/aoc_21_5_input.txt", 'utf8')
const drawing = (straight) => input.split('\n').reduce((acc, line) => {
let [[x1,y1],[x2,y2]] = line.split(' -> ').map(x => x.split(',').map(x => parseInt(x)))
if (straight && x1!=x2 && y1!=y2) return acc