Skip to content

Instantly share code, notes, and snippets.

@cfrank
cfrank / shortest-path-binary-matrix.ts
Created June 2, 2023 19:07
1091. Shortest Path in Binary Matrix
function shortestPathBinaryMatrix(grid: number[][]): number {
const getDirections = ([row, col]: [number, number]): number[][] => {
const canMove = ([row, col]: [number, number]) => {
return (row >= 0 && row < grid.length) && (col >= 0 && col < grid[row].length)
}
// Given a 3x3 matrix with row/col index of [1,1]
// we should return:
//
// [0, 1] == North
@cfrank
cfrank / can-place-flowers.ts
Created June 1, 2023 20:21
605. Can Place Flowers
function canPlaceFlowers(flowerbed: number[], n: number): boolean {
let openPlots = 0;
for (let i = 0; i < flowerbed.length; ++i) {
if (flowerbed[i] === 1) {
continue;
}
const leftSideFree = (i === 0 || flowerbed[i - 1] === 0);
const rightSideFree = (i + 1 >= flowerbed.length || flowerbed[i + 1] === 0);
@cfrank
cfrank / longest-zig-zag-binary-tree.ts
Last active June 5, 2023 17:36
1372. Longest ZigZag Path in a Binary Tree
/**
* Definition for a binary tree node.
* class TreeNode {
* val: number
* left: TreeNode | null
* right: TreeNode | null
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
@cfrank
cfrank / max-vowels-substring.js
Created June 1, 2023 18:21
1456. Maximum Number of Vowels in a Substring of Given Length
const VOWELS = ['a', 'e', 'i', 'o', 'u'];
/**
* @param {string} str
* @param {number} frameSize
* @return {number}
*/
var maxVowels = function(str, frameSize) {
// Given a char return true if it's a vowel
const isVowel = (char) => VOWELS.includes(char);
@cfrank
cfrank / underground_system.js
Created May 31, 2023 23:51
1396. Design Underground System
class UndergroundSystem {
#stationTripLengthMap;
#inFlightTrips;
constructor() {
this.#stationTripLengthMap = {};
this.#inFlightTrips = {};
}
checkIn(id, stationName, t) {
@cfrank
cfrank / ContainerWindow.cpp
Last active May 1, 2023 08:12
Implementation of a container window for the CEF browser window - In the end this was not needed.
// SPDX-License-Identifier: BSD-2-Clause
#include <iostream>
#include <sys/select.h>
// #include "ContainerWindow.hpp"
class ContainerWindow {
public:
struct Delegate {
virtual void OnContainerWindowCreate(xcb_window_t) const = 0;
@cfrank
cfrank / jagex-appletviewer-compile.md
Last active October 9, 2022 08:23
Compile jagexappletviewer on Java 1.6

These are not the original file paths. Adapt the file locations to something that matches what you have.

C:\Program Files (x86)\Java\jdk1.6.0_45\bin\javac.exe' -cp .\src\main\java\ -d .\tmp-cmd-dir-cl\ .\src\main\java\com\open592\appletviewer\*.java .\src\main\java\com\open592\jagexappletviewer\*.java .\src\main\java\com\open592\nativeadvert\*.java

C:\Program Files (x86)\Java\jdk1.6.0_45\bin\jar.exe' -cvfe jagexappletviewer.jar com.open592.jagexappletviewer.jagexappletviewer .\com\open592\jagexappletviewer\*.class .\com\open592\appletviewer\*.class .\com\open592\nativeadvert\*.class

$env:JAVA_TOOL_OPTIONS = '-Dcom.jagex.config=http://localhost:8000/jav_config.ws'

C:\Program Files (x86)\Java\jdk1.6.0_45\bin\java.exe' -jar .\jagexappletviewer.jar runescape

@cfrank
cfrank / 592-game-applet-html-block.html
Last active August 17, 2022 07:07
HTML of the <applet> code block for the 592 revision of Runescape
<!--
This is the <applet> block for the 592 revision of RuneScape as it appeared on:
16:13:13 Feb 25, 2010
Some of these values are dynamic and determined by the URL being requested, the browser, and the JavaScript which
gets executed after the HTML is loaded. Because of this you can't use these as a source of truth for the final
parameters without taking that into account.
-->
@cfrank
cfrank / kotlin-event-bus-playground.kt
Last active July 5, 2022 09:03
Kotlin event bus playground
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.*
sealed class AppEvent {
data class Initialized(val timestamp: Long) : AppEvent()
class Bootstrapped() : AppEvent()
data class Loaded(val timestamp: Long) : AppEvent()
}
class EventBus {
@cfrank
cfrank / 592-jav_config.ws
Last active April 10, 2024 08:58
592 jav_config.ws file - Will update as more debugging / deobfuscating is done on applications.
title=RuneScape
viewerversion=100
serverlist=http://127.0.0.1:8000/jav_config_serverlist.ws
cachesubdir=runescape
codebase=http://127.0.0.1:8000/
browsercontrol_win_x86_jar=browsercontrol_0_-1928975093.jar
browsercontrol_win_amd64_jar=browsercontrol_1_1674545273.jar
loader_jar=loader.jar
advert_height=96
window_preferredwidth=1024