Skip to content

Instantly share code, notes, and snippets.

View johngian's full-sized avatar

John Giannelos johngian

View GitHub Profile
@johngian
johngian / beautify-html.py
Created January 23, 2024 11:14
Beautify HTML using beautiful soup
import click
from bs4 import BeautifulSoup
@click.command()
@click.argument("path")
def main(path):
with open(path, "r") as f:
html = f.read()
pretty = BeautifulSoup(html).prettify()
@johngian
johngian / README.md
Last active January 12, 2024 08:56
Mock imported class from module using sinon

Context

Sinon design is mostly focused on mocking/stubbing function instead of class definitions. Its easy to mock class functions (via mocking/stubbing the prototype) but having a side effect on constructor makes things complicated.

Solution

One work around to this is using the sinon.createStubInstance(constructor) method and then add a fake call to the class.

use std::fs;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use itertools::Itertools;
pub fn parse_input(path: PathBuf) -> std::io::Lines<std::io::BufReader<std::fs::File>> {
let file: fs::File = fs::File::open(path).unwrap();
let buf: BufReader<fs::File> = std::io::BufReader::new(file);
buf.lines()
}
@johngian
johngian / aoc-day-1-pt2.rs
Last active December 1, 2023 13:56
AoC Day 1 - Part 2
use std::fs;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
const WORDS: [(&str, u32); 10] = [
("zero", 0),
("one", 1),
("two", 2),
("three", 3),
("four", 4),
@johngian
johngian / git-archive.sh
Last active July 4, 2022 09:16
Archive local branches
git for-each-ref --format='%(refname:short)' refs/heads/ | grep -v -E 'production|master|main' | xargs -I {} git tag archive/{}/$(date +%s)
git for-each-ref --format='%(refname:short)' refs/heads/ | grep -v -E 'production|master|main' | xargs -I {} git branch -D {}
# Parsoid file activity since 2021-11-01
root@90e17d94e6ce:/srv/parsoid# git log --since="2021-11-01" --name-status --pretty=format: -- "${ARGV[@]+"${ARGV[@]}"}" | cut -f 2- | /srv/git-heatmap/git-heatmap --filter "grep -v tests | grep -v package.json | grep -v compsoer.json | grep .php" -n 100
src/Config/Env.php | 130 | ████████████████████████████████████████████████████████████
src/Html2Wt/WikitextSerializer.php | 125 | ██████████████████████████████████████████████████████████
src/Wt2Html/TT/TemplateHandler.php | 123 | █████████████████████████████████████████████████████████
src/Ext/Cite/References.php | 122 | ████████████████████████████████████████████████████████
extension/src/Rest/Handler/ParsoidHandler.php | 116 | ██████████████████████████████████████████████████████
src/Wt2Html/DOMPostProcessor.php | 113 | ████████████████████████████████
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@johngian
johngian / advent-of-code-2021-day9-part-1.ex
Created December 10, 2021 10:26
Advent of code 2021 - day 9 - part 1 - solution
defmodule Smoke do
def read(path) do
[h | t] =
File.read!(path)
|> String.split("\n")
|> Enum.map(fn x ->
String.codepoints(x)
|> Enum.map(&String.to_integer/1)
|> (fn x -> [10] ++ x ++ [10] end).()
end)