Skip to content

Instantly share code, notes, and snippets.

View juliarose's full-sized avatar

Julia juliarose

  • United States
View GitHub Profile
function createBencher(iters) {
return function runBench(label, fn) {
console.time(label);
for (let i = 0; i < iters; i++) {
fn();
}
console.timeEnd(label);
@juliarose
juliarose / color.js
Last active July 2, 2024 06:45
Efficient color utility functions.
// @ts-check
/**
* Lightens a color.
* @param {string} color - Hexadecimal number string of color.
* @param {number} [ratio=0.5] - Strength of effect.
* @returns {(string | null)} 6-digit hexadecimal number string of result.
*/
export function lighten(color, ratio = 0.5) {
ratio = clampRatio(ratio);
/**
* @brief Checks if a string ends with a given suffix.
*
* @param fullString The string to check.
* @param ending The suffix to check for.
* @return True if the string ends with the suffix, false otherwise.
*/
bool hasEnding(std::string const &fullString, std::string const &ending) {
// Sourced from https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c
int fullStringLen = fullString.length();
@juliarose
juliarose / ffmpeg-trim-video.sh
Created May 28, 2024 02:53
Trims a video from a set point to a set duration.
ffmpeg -ss 00:01:07 -i input.mkv -t 00:28:26 -vcodec copy -acodec copy -avoid_negative_ts make_zero output.mkv
@juliarose
juliarose / Cobol.cbl
Created April 20, 2024 00:39
A simple COBOL template without line numbers.
*Format lines:
* awk -i inplace '{printf("%04d00%s\n", NR, substr($0,7,120)) }' main.cbl
*Compile and run:
* cobc -x main.cbl && ./main
IDENTIFICATION DIVISION.
PROGRAM-ID. hello.
AUTHOR. Julia.
DATE-WRITTEN. 2024-04-19.
DATE-COMPILED. 2024-04-19.
REMARKS. This is a pretty good COBOL program.
@juliarose
juliarose / variables-and-operations.cbl
Last active April 16, 2024 17:55
Storing different variables and performing operations in COBOL.
000100*Condensed from 01-06 https://www.youtube.com/watch?v=m0HfCx1wg1g
000200*AAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBIIIIIIII
000300 IDENTIFICATION DIVISION.
000400 PROGRAM-ID. hello.
000500 AUTHOR. JULIA.
000600 DATE-WRITTEN. 2024-04-16.
000700 DATE-COMPILED. 2024-04-16.
000800 REMARKS. This is a pretty good COBOL program.
000900*
001000 ENVIRONMENT DIVISION.
@juliarose
juliarose / Cobol.cbl
Last active April 16, 2024 17:39
A simple COBOL template.
000100*AAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBIIIIIIII
000150*Format lines:
000151* awk -i inplace '{printf("%04d00%s\n", NR, substr($0,7,120)) }' main.cbl
000160*Compile and run:
000161* cobc -x main.cbl && ./main
000200 IDENTIFICATION DIVISION.
000400 PROGRAM-ID. hello.
000500 AUTHOR. JULIA.
000600 DATE-WRITTEN. 2024-04-14.
000700 DATE-COMPILED. 2024-04-14.
@juliarose
juliarose / addRefineds.js
Created April 5, 2024 19:47
Demonstrates one method of adding floating-point refined metal values in JavaScript.
// Source:
// https://github.com/Nicklason/node-tf2-currencies
const ONE_REF_SCRAP = 9;
// Convert a number in refined to scrap
function toScrap(refined) {
return Math.round(refined * ONE_REF_SCRAP);
}
// A possibly more efficient way to match pluralized strings case-insensitively.
// For example matching "burgers" and "burger" with fewer iterations.
// Untested
fn eq_ignore_ascii_case_with_tail(mut lhs: &str, rhs: &str, tail: char) -> bool {
let mut lhs_len = lhs.len();
let rhs_len = rhs.len();
if lhs_len == rhs_len + 1 && lhs.ends_with(tail) {
lhs = &lhs[..lhs_len - 1];
@juliarose
juliarose / iterators.js
Last active February 6, 2024 14:55
hello world in JavaScript
const Filtered = Symbol('Filtered');
const Break = Symbol('Break');
class CharIterator {
constructor(string) {
this.string = string;
this.index = 0;
}