Skip to content

Instantly share code, notes, and snippets.

View josemarcosrf's full-sized avatar
🏔️
Working from a mountain top

Jose Marcos RF josemarcosrf

🏔️
Working from a mountain top
View GitHub Profile
@josemarcosrf
josemarcosrf / midv-500-stream.py
Last active October 19, 2021 20:04
Stream data from an s3 like bucket (e.g: DigitalOcean spaces) directly into memory. (midv-500 dataset streaming example)
import json
import os
import tarfile
import numpy as np
import cv2
import matplotlib.pyplot as plt
from collections import defaultdict
@josemarcosrf
josemarcosrf / get-npm-package-version
Last active June 21, 2021 09:30 — forked from DarrenN/get-npm-package-version
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
cat ./package.json | grep -m 1 version | sed 's/[^0-9.]//g'
echo $PACKAGE_VERSION
@josemarcosrf
josemarcosrf / gdrive_download.sh
Created March 19, 2021 10:11
Download Google Drive file with wget
#!/usr/bin/env bash
set -e
set -o pipefail
say() {
echo "$@" | sed \
-e "s/\(\(@\(red\|green\|yellow\|blue\|magenta\|cyan\|white\|reset\|b\|u\)\)\+\)[[]\{2\}\(.*\)[]]\{2\}/\1\4@reset/g" \
-e "s/@red/$(tput setaf 1)/g" \
-e "s/@green/$(tput setaf 2)/g" \
@josemarcosrf
josemarcosrf / g_sheet_functions.gs
Created February 25, 2021 12:26
Google Docs (sheets, docs, etc) helper functions
/**
* Returns the URL of a hyperlinked cell, if it's entered with hyperlink command.
* Supports ranges
* @param {A1} reference Cell reference
* @customfunction
*/
function linkURL(reference) {
var sheet = SpreadsheetApp.getActiveSheet();
var formula = SpreadsheetApp.getActiveRange().getFormula();
var args = formula.match(/=\w+\((.*)\)/i);
@josemarcosrf
josemarcosrf / configure_cuda_with_xorg_in_cpu.md
Created February 20, 2021 21:01 — forked from alexlee-gk/configure_cuda_p70.md
Use integrated graphics for display and NVIDIA GPU for CUDA on Ubuntu 14.04

This was tested on a ThinkPad P70 laptop with an Intel integrated graphics and an NVIDIA GPU:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204GLM [Quadro M3000M] (rev a1)

A reason to use the integrated graphics for display is if installing the NVIDIA drivers causes the display to stop working properly. In my case, Ubuntu would get stuck in a login loop after installing the NVIDIA drivers. This happened regardless if I installed the drivers from the "Additional Drivers" tab in "System Settings" or the ppa:graphics-drivers/ppa in the command-line.

@josemarcosrf
josemarcosrf / clean_disk.sh
Created January 14, 2021 19:28
Script to clean up and free disk space in Linux; Docker, Snap, cache, etc
#!/bin/bash
set -eu
set -o pipefail
say() {
echo "$@" | sed \
-e "s/\(\(@\(red\|green\|yellow\|blue\|magenta\|cyan\|white\|reset\|b\|u\)\)\+\)[[]\{2\}\(.*\)[]]\{2\}/\1\4@reset/g" \
-e "s/@red/$(tput setaf 1)/g" \
-e "s/@green/$(tput setaf 2)/g" \
@josemarcosrf
josemarcosrf / vm_setup.sh
Last active March 4, 2024 22:02
Shell script to do the first setup install of utilities and minimum dev tools on a clean Ubuntu (Anaconda, Docker, ...)
#!/usr/bin/env bash
# set -e
# set -o pipefail
say() {
echo "$@" | sed \
-e "s/\(\(@\(red\|magenta\|yellow\|blue\|magenta\|cyan\|white\|reset\|b\|u\)\)\+\)[[]\{2\}\(.*\)[]]\{2\}/\1\4@reset/g" \
-e "s/@red/$(tput setaf 1)/g" \
@josemarcosrf
josemarcosrf / py_context_managers.py
Last active October 13, 2023 16:14
Python helper functions, decorators and context managers
import signal
from contextlib import contextmanager
from time import perf_counter
@contextmanager
def timeout(duration: int):
def timeout_handler(signum, frame):
raise Exception(f"Block timed out after {duration} seconds")
@josemarcosrf
josemarcosrf / closure_vs_recusive.py
Created December 9, 2020 21:27
closure vs recursive functions to process a tree-like recursive structure
import json
from collections import deque
from functools import wraps
from pprint import pformat
from time import time
from typing import List
from typing import Text
@josemarcosrf
josemarcosrf / async_gather_async_callback.py
Last active February 23, 2021 15:35
Async python simple example
import asyncio
import requests
import numpy as np
import time
from functools import wraps
from typing import Callable
REQUEST_BATCH_SIZE = 250