Skip to content

Instantly share code, notes, and snippets.

View ammachado's full-sized avatar

Adriano Machado ammachado

  • Red Hat
  • 09:10 (UTC -05:00)
View GitHub Profile
@ammachado
ammachado / docker-unpack.py
Created June 28, 2018 21:39 — forked from bencord0/docker-unpack.py
Unpack a docker image.
#!/usr/bin/env python
import argparse
import json
import os
import sys
import tarfile
parser = argparse.ArgumentParser()
parser.add_argument(
'--image', '-i', required=True,
@ammachado
ammachado / AbstractTestsWithH2Rollback
Created June 28, 2018 21:37 — forked from brookslyrette/AbstractTestsWithH2Rollback
java backup and restore of h2 for unit tests
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {SampleApplication.class}, name = "acceptanceTestContext")
@WebIntegrationTest
public abstract class AbstractAcceptanceTests {
@Autowired
protected JdbcTemplate jdbcTemplate;
/**
* Backs up the database before running this test.
@ammachado
ammachado / filename.sh
Created March 6, 2018 23:05 — forked from cuschk/filename.sh
Bash: file base name and extension
#!/usr/bin/env bash
f='/path/to/example.txt'
base="${f##*/}"
echo $base
#=> example.txt
echo "${base%.*}"
@ammachado
ammachado / gist:bdf24a5405aa55f07ccf4aadaf1fdf19
Created March 6, 2018 21:46 — forked from jordelver/gist:5304643
zsh file renaming using zmv

zsh file renaming using zmv

Load the zmv function, best place is in ~/.zshrc

autoload zmv

Rename files using regex captures

Take filenames likes image0001.jpg and rename to 0001.jpg

@ammachado
ammachado / filename.zsh
Created March 6, 2018 21:33 — forked from cuschk/filename.zsh
Zsh: file base name and extension
#!/usr/bin/env zsh
f='example.txt'
echo ${f:r}
#=> example
echo ${f:e}
#=> txt
@ammachado
ammachado / README.md
Created November 30, 2017 19:28 — forked from dannguyen/README.md
Using Python 3.x and Google Cloud Vision API to OCR scanned documents to extract structured data

Using Python 3 + Google Cloud Vision API's OCR to extract text from photos and scanned documents

Just a quickie test in Python 3 (using Requests) to see if Google Cloud Vision can be used to effectively OCR a scanned data table and preserve its structure, in the way that products such as ABBYY FineReader can OCR an image and provide Excel-ready output.

The short answer: No. While Cloud Vision provides bounding polygon coordinates in its output, it doesn't provide it at the word or region level, which would be needed to then calculate the data delimiters.

On the other hand, the OCR quality is pretty good, if you just need to identify text anywhere in an image, without regards to its physical coordinates. I've included two examples:

####### 1. A low-resolution photo of road signs

@ammachado
ammachado / IterableListScrollableResults.java
Created November 3, 2017 20:55 — forked from ymartin59/IterableListScrollableResults.java
IterableListScrollableResults<E> is a partial wrapper view as a List<E> on an Hibernate ScrollableResults. When an existing code process a large amount of Hibernate entities as a List<E>, it allows to work with data in stream without a large code refactoring.
import java.util.AbstractList;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
/**
* A List<E> partial wrapper view on an Hibernate ScrollableResults.

Keybase proof

I hereby claim:

  • I am ammachado on github.
  • I am ammachado (https://keybase.io/ammachado) on keybase.
  • I have a public key whose fingerprint is 0431 9C8C 62E2 DE3A 9C93 D941 6BFB CD48 6D0D A70B

To claim this, I am signing this object:

@ammachado
ammachado / jenkins-backup-job-config.py
Created June 15, 2017 05:22 — forked from glombard/jenkins-backup-job-config.py
Backup the config.xml of Jenkins jobs using the REST API
import logging
import requests
logging.captureWarnings(True)
SERVER = 'my-jenkins'
JOB_FILTER = 'test'
API_TOKEN = '<my-jenkins-api-token>'
USER = 'glombard'
@ammachado
ammachado / Enum.es6.js
Created April 21, 2017 06:01 — forked from xmlking/Enum.es6.js
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;