Skip to content

Instantly share code, notes, and snippets.

View ChrisVilches's full-sized avatar

Chris Vilches ChrisVilches

View GitHub Profile
@ChrisVilches
ChrisVilches / kindle_highlight_clean.py
Last active July 6, 2022 16:10
Clean HTML files generated by the Windows Kindle app when exporting highlights.
import sys
import re
# TODO: The main code should be inside a __main__, I think.
FILE = sys.argv[1]
file = open(FILE, "r", encoding="utf8")
data = file.read()
file.close()
@ChrisVilches
ChrisVilches / ostream_istream_overload.cpp
Created May 31, 2022 20:33
How to print and read custom data in C++.
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y;
};
ostream& operator<<(ostream& os, const Point& p) {
return os << "(" << p.x << ", " << p.y << ")";
}
@ChrisVilches
ChrisVilches / vscode_fix_rubocop.md
Last active January 21, 2022 12:53
Fix VSCode RuboCop error

RuboCop (VSCode) bundle not found error

Fix the error bundle not found error or something similar. This happens when the rubocop VSCode extension is set to execute using bundle exec.

Open this file:

~/.vscode/extensions/misogi.ruby-rubocop-0.8.6/out/src/configuration.js
@ChrisVilches
ChrisVilches / search-text.sh
Created December 25, 2021 19:16
Search text (inside files) in directory recursively in Linux
search-text(){
if [ ! -z "$1" ]
then
grep --exclude-dir={.git,tmp,log,node_modules,vendor} -r "$1" .
fi
}
# Example usage:
# search-text "with a suffix tree"
@ChrisVilches
ChrisVilches / hide_name_terminal.sh
Last active November 2, 2021 10:35
Remove name in terminal (i.e. leave only the $)
# Note: Execute directly on the terminal (it has no effect if it's inside a bash script)
export PS1="\$ "
@ChrisVilches
ChrisVilches / c++
Last active April 25, 2022 09:37
C++ Runner
#!/bin/bash
# A bash utility for quickly running a simple C++ file using:
# c++ my_file.cpp
#
# Features:
# * stderr output becomes red (use std::cerr or fprintf(stderr, ...) to debug).
# * Caches the compiled file based on the code content (if the file doesn't change,
# it will run the same pre-compiled binary).
#
// normalizeTitle :: String -> String
const normalizeTitle = rawTitle => {
const parts = rawTitle.split(" - ");
const right = parts[1].toLowerCase().replace(/\s/g, "_").replace(/[^a-z_0-9]+/g, "");
return `${parts[0]}-${right}`;
}
const rawTitle = document.getElementById("problem-name").innerHTML;
@ChrisVilches
ChrisVilches / mednafen-console-gui.js
Last active October 23, 2018 02:31
Mednafen Console GUI
const fs = require("fs");
const path = require ("path");
const readline = require('readline');
const { spawn } = require('child_process');
let ROMS_FOLDER = "C:/Users/.../PSX";
let MEDNAFEN_HOME = "C:/Users/.../Mednafen";
// Initialize the line reader
const rl = readline.createInterface({
@ChrisVilches
ChrisVilches / animated_number_WIP
Created August 27, 2018 19:17
React Component - Animated Number (WIP)
https://codesandbox.io/s/o5r159mpkq
@ChrisVilches
ChrisVilches / paragraphs.js
Created August 23, 2018 20:55
Converts a multiline string into a <p>...</p> separated string for HTML use.
function toParagraphs(string){
return string.split(/[\r?\n]+/g)
.map(p => p.trim())
.filter(p => p.length > 0)
.map(p => `<p>${p}</p>`)
.join("");
}
// Tests