Skip to content

Instantly share code, notes, and snippets.

@evandrocoan
evandrocoan / convert_yaml_json.py
Created January 10, 2023 00:53
Convert Anki decks from JSON to YAML and vice versa.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import timeit
import datetime
import argparse
import tempfile
import pathlib
@evandrocoan
evandrocoan / .gitignore
Last active March 11, 2024 15:04
Simple C++ program example to run tests together with your code using doctest.
/build
@evandrocoan
evandrocoan / JSONLexer.py
Created April 6, 2022 22:47 — forked from erezsh/JSONLexer.py
Parsers used for Lark benchmarks
# Generated from JSON.g4 by ANTLR 4.7.1
# encoding: utf-8
from __future__ import print_function
from antlr4 import *
from io import StringIO
import sys
def serializedATN():
with StringIO() as buf:
@evandrocoan
evandrocoan / git_subbree.md
Last active January 18, 2022 12:22
Using git subtree to export a directory (with its history) from one git repository to another

Using git subtree to export a directory (with its history) from one git repository to another:

  1. git subtree add --prefix=local_directory https://github.com/account_name/other_project_to_commits master
  2. git subtree pull --prefix=local_directory https://github.com/account_name/other_project_to_commits develop
  3. git subtree push --prefix=local_directory https://github.com/account_name/other_project_to_commits develop

If you prefer to avoid repeating the repository URL, then you can add it as a remote:

  1. git remote add -f -t master --no-tags remote_name https://github.com/account_name/other_project_to_commits.git

Examples of remote name and local .git directory:

  1. git subtree add --squash --prefix=local_directory file:///D:/other_project_to_commits/.git master
@evandrocoan
evandrocoan / generate_certificate.sh
Created January 5, 2022 13:05
Generated an ssl private/public SSL certificate
#!/bin/bash
set -x
set -eu -o pipefail
function printerror
{
set +x
printf '\n'
printf 'Usage\n'
printf ' %s "key name" "key password" "servidor ip" "server name (i.e., $HOSTNAME)"\n' "$0"
@evandrocoan
evandrocoan / copy_and_move.md
Last active April 24, 2022 23:33
Copy and move constructor example, rule of 5
@erezsh
erezsh / JSONLexer.py
Created December 13, 2021 08:54
Parsers used for Lark benchmarks
# Generated from JSON.g4 by ANTLR 4.7.1
# encoding: utf-8
from __future__ import print_function
from antlr4 import *
from io import StringIO
import sys
def serializedATN():
with StringIO() as buf:
import pathlib
ROOT_DIR = pathlib.Path(__file__).parent.parent

process, output = run_process(f"python3 {ROOT_DIR / 'something.py'}", ROOT_DIR)
process = run_background(f"python3 {ROOT_DIR / 'something.py'}", ROOT_DIR)
@evandrocoan
evandrocoan / git-extract-file.markdown
Created October 5, 2021 20:32 — forked from ssp/git-extract-file.markdown
Extract a single file from a git repository

How to extract a single file with its history from a git repository

These steps show two less common interactions with git to extract a single file which is inside a subfolder from a git repository. These steps essentially reduce the repository to just the desired files and should performed on a copy of the original repository (1.).

First the repository is reduced to just the subfolder containing the files in question using git filter-branch --subdirectory-filter (2.) which is a useful step by itself if just a subfolder needs to be extracted. This step moves the desired files to the top level of the repository.

Finally all remaining files are listed using git ls, the files to keep are removed from that using grep -v and the resulting list is passed to git rm which is invoked by git filter-branch --index-filter (3.). A bit convoluted but it does the trick.

1. copy the repository to extract the file from and go to the desired branch