Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View justinledwards's full-sized avatar

Justin Edwards justinledwards

  • Florida Ninth Circuit Courts
  • Florida
View GitHub Profile
@justinledwards
justinledwards / game.rb
Last active November 23, 2023 15:15
ruby 2d tic tac toe
# frozen_string_literal: true
require 'ruby2d'
# This class represents the game board.
class Board
attr_accessor :cells
def initialize
@cells = Array.new(3) { Array.new(3, '') }
@justinledwards
justinledwards / chat-gpt-code-fail.md
Created November 19, 2023 17:43
Seeing if chatgpt can figure out how to solve tests.
class RacingGame:
    def __init__(self, width, height, road_width):
        self.width = width
        self.height = height
        self.road_width = road_width
        self.car_position = width // 2 + 1  # Adjusted to stay on the right
        self.road_offset = 0
        self.road_direction = 1
        self.game_over = False
@justinledwards
justinledwards / junos_recommend.py
Created November 5, 2023 20:55
Get Recommended Junos Versions
from playwright.sync_api import sync_playwright
from bs4 import BeautifulSoup
def extract_data(page_content):
soup = BeautifulSoup(page_content, 'html.parser')
series_list = ["EX Series Ethernet Switches", "ACX Series Service Routers",
"J Series Service Routers", "QFX Series Service Routers",
"SRX Series Services Gateways"]
for series in series_list:
@justinledwards
justinledwards / Cargo.toml
Last active November 2, 2023 21:26
i love lamp
[package]
name = "rust-lavalamp"
version = "0.1.0"
edition = "2018"
# Dependencies
[dependencies]
rand = "0.8"
ncurses = "5.101.0"
@justinledwards
justinledwards / snakecheat.js
Created September 13, 2023 12:43
Snake cheat
let e=e=>new Promise(t=>setTimeout(t,e)),c=e=>e.charCodeAt(),a=e=>"Arrow"+e,k=e=>{let t=new KeyboardEvent("keydown",{key:e,code:e,keyCode:c(e),which:c(e)});document.dispatchEvent(t)},t=(t,o)=>e(t).then(()=>k(a(o))),l=async()=>{for(let e=0;e<1e9;e++)await t(30,"Left"),await t(720,"Up"),await t(30,"Right"),await t(780,"Up")};e(90).then(l);

On-Page JavaScript Console.

ChatGPT:

Creating a simple on-page JavaScript console or REPL can be achieved with a combination of HTML, CSS, and JavaScript. You can use localStorage to maintain state between sessions. Here's a basic implementation that you can use as a starting point and modify to fit your needs:

  1. First, create the HTML structure for your on-page console:
<!DOCTYPE html>
<html lang="en">
@justinledwards
justinledwards / Cargo.toml
Created May 2, 2023 16:41
Rust Snake GUI
[package]
name = "snake"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
piston_window = "0.128.0"
rand = "0.8.5"
@justinledwards
justinledwards / ChatGPT-Node.js_Data_Joins.md
Created April 26, 2023 20:48
Mongo vs Sql code styles

Node.js Data Joins

You:

Can you write some example code for nodejs for fairly normal data joins from mysql using a common library vs mongodb as just a single document to make the same objects on both?

ChatGPT:

Sure, I can provide you with example code for both MySQL and MongoDB using Node.js. We'll use mysql2 library for MySQL and mongodb library for MongoDB. I'll assume you have both databases set up, and we'll retrieve data from two tables/collections, users and orders, and join them on the user_id field.

First, let's install the necessary libraries:

@justinledwards
justinledwards / helper.js
Last active April 7, 2023 18:34
Florida Court Case Number Format
export const parseFloridaCourtCaseNumber = (caseNumber) => {
// Regular expression pattern to match Florida court case numbers with optional extra hyphens
const pattern = /^(\d{4})-(\w{2})-(\d{6})(?:-([A-Za-z0-9]+))?(?:-([A-Za-z0-9]+))?$/;
const match = caseNumber.match(pattern);
if (match) {
const [, year, caseTypeAbbrev, sequenceNumber, optionalPart1, optionalPart2] = match;
// Map case type abbreviations to their corresponding strings
const caseTypeMap = {
@justinledwards
justinledwards / snake.mjs
Last active April 3, 2023 18:54
CLI Snake with nodejs chalk and keypress
import chalk from 'chalk';
import keypress from 'keypress';
// npm i chalk keypress
keypress(process.stdin);
const width = process.stdout.columns;
const height = process.stdout.rows - 1;