Skip to content

Instantly share code, notes, and snippets.

View johngian's full-sized avatar

John Giannelos johngian

View GitHub Profile
@johngian
johngian / mapnik.Dockerfile
Last active August 30, 2024 16:37
Build mapnik and node-mapnik from source
FROM debian:bookworm
RUN apt-get update
RUN apt-get install -y build-essential python3 libboost-all-dev libharfbuzz-dev \
libtiff-dev libicu-dev zlib1g-dev libfreetype-dev libxml2-dev libpng-dev \
libwebp-dev libproj-dev libcairo2-dev python3 python3-dev git libjpeg-dev libgdal-dev \
nodejs npm
RUN git clone https://github.com/mapnik/mapnik.git /srv/mapnik
RUN git clone https://github.com/mapnik/node-mapnik /srv/node-mapnik
@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 | ████████████████████████████████
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.