Skip to content

Instantly share code, notes, and snippets.

@JoseHdez2
JoseHdez2 / todo_lines_csv.sh
Last active November 7, 2022 09:28
Get all TODO lines of a repo as a CSV file
git grep -l TODO | xargs -n1 git blame -fe --date=short | grep TODO | sed -E 's#\(#,\(#; s#<([a-z]+@[a-z]+\.com)>#,\1,#; s#([0-9]{4}-[0-9]{2}-[0-9]{2})#\1,#; s@(\/\/|#|\/\*)(.*TODO.*)@,"\1\2"@; s#[0-9a-f]{10}##' > todos_$(date +%s).csv
@JoseHdez2
JoseHdez2 / AnkiDeckMediaExtractor.py
Created September 4, 2022 21:14 — forked from 0187773933/AnkiDeckMediaExtractor.py
Anki Deck Media Extractor
#!/usr/bin/env python3
import sys
import io
import zipfile
import tempfile
from pathlib import Path
import sqlite3
import json
import shutil
@JoseHdez2
JoseHdez2 / join.ts
Last active August 3, 2022 12:27
Generic version of String.join().
/** `zip([a, b, c], [1, 2, 3] => [[a, 1], [b, 2], [c, 3]])` */
const zip = (a: Array<any>, b: Array<any>) =>
Array.from(Array(Math.max(b.length, a.length)), (_, i) => [a[i], b[i]]);
/** Generic version of String.join(). Add a separator element between each of the elements. */
const join = (a: Array<any>, separator: any) =>
zip(a, Array(a.length - 1).fill(separator))
.flat()
.splice(-1);
import random
import string
# https://pynative.com/python-generate-random-string/
def randomString(stringLength=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
/**
* Use to wrap a block of code in a test that should throw an exception.
* @param errorMsg Message to show if the block of code DOESN'T throw an exception. Optional.
* @param withExceptionHaving Substring that the thrown exception must contain. Optional.
* Checking exception strings is generally discouraged, and will cause the need to
* periodically readjust the expected strings, but it guarantees the error is the expected one.
*/
fun shouldFail(errorMsg: String = "Should have failed.", withExceptionHaving: String? = null, method: () -> Unit) {
try {
method()
@JoseHdez2
JoseHdez2 / sort-by-date.sh
Created November 25, 2019 09:48
Sort files in current directory into folders by date (YYYY-MM-DD)
#!/bin/bash
for x in *.*; do
d=$(date -r "$x" +%Y-%m-%d)
mkdir -p "$d"
mv -- "$x" "$d/"
done
@JoseHdez2
JoseHdez2 / range.js
Created November 4, 2019 23:56
range in ECMAscript 6
// https://www.westworld.be/range-in-es6/
//range from 0 => n
const range =[...Array(n).keys()];
console.log(range);
//Range from start => end
@JoseHdez2
JoseHdez2 / .gitconfig
Created October 23, 2019 11:44
Git config with aliases
[alias]
alias = config --get-regexp ^alias\\.
co = checkout
cob = checkout -b
logtree = log --all --decorate --oneline --graph
logi = log --oneline
c = commit -m
ac = commit -am
cp = cherry-pick
b = branch
if(pm.environment.get("key") === undefined){
pm.environment.set("key", "value");
}
@JoseHdez2
JoseHdez2 / eclipse-shortcuts.md
Last active October 23, 2019 11:45
Some Eclipse shortcuts
  • Most important:
    • F3 / Ctrl+click: Go to declaration.
    • Ctrl+Alt+H: show all uses (calls) of a method.
    • Alt+Left: previous cursor position.
  • Important:
    • F4: show Type Hierarchy.
    • Ctrl+O: search for method in class (great for navigating big classes).
  • Others:
    • Ctrl+Shift+F: Format selection.
  • Alt+Shift+A: Toggle block-editing mode.