Skip to content

Instantly share code, notes, and snippets.

View jimmytuc's full-sized avatar
💭
I may be slow to respond.

Foo jimmytuc

💭
I may be slow to respond.
  • Viet Nam
View GitHub Profile
@jimmytuc
jimmytuc / parse.js
Last active August 29, 2015 14:22 — forked from stephenfeather/parse.js
// Copyright Stephen Feather and other contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@jimmytuc
jimmytuc / php
Last active October 14, 2015 04:07
PHP str_replace customization to adapt multi array element passing as argument1 & argument2
function p_str_replace($argFind, $agrReplace, $theString) {
$needle_replace = $theString; // handle the string need to be replace
array_walk($argFind, function($val, $key) use(&$needle_replace, $agrReplace) {
$needle_replace = call_user_func_array('str_replace', array($val, $agrReplace[$key], $needle_replace));
});
return $needle_replace;
}
// testing purpose
$the_str = array(
@jimmytuc
jimmytuc / README.md
Created July 5, 2016 23:34 — 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

@jimmytuc
jimmytuc / nextTick.js
Created July 23, 2017 05:31 — forked from mmalecki/nextTick.js
process.nextTick vs setTimeout(fn, 0)
for (var i = 0; i < 1024 * 1024; i++) {
process.nextTick(function () { Math.sqrt(i) } )
}
@jimmytuc
jimmytuc / RunScheduler.php
Created February 26, 2018 07:47 — forked from robbydooo/RunScheduler.php
Heroku Laravel Scheduler
<?php
/**
This Scheduler will run once every minute unlike the Heroku scheduler which only runs every 10 mintues.
To use this scheduler with Laravel 5.4+ add this file to /app/Console/Commands/RunScheduler.php
Register this file in app/Console/Kernel.php
@jimmytuc
jimmytuc / docker-cleanup-resources.md
Created April 4, 2018 04:41 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@jimmytuc
jimmytuc / CONCURRENCY.md
Created August 16, 2018 04:12 — forked from montanaflynn/CONCURRENCY.md
Examples of sequential, concurrent and parallel requests in node.js

Concurrency in JavaScript

Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.

@jimmytuc
jimmytuc / read_big_file.py
Created November 2, 2018 07:41
Read big file by splitting chunks & seeking file parts
#/usr/bin/python3
import multiprocessing as mp
import os
def process_each_chunk(file, chunk_start, chunk_size):
with open(file) as f:
f.seek(chunk_start)
lines = f.read(chunk_size).splitlines()
for line in lines:
@jimmytuc
jimmytuc / ref_es_queries.md
Created November 21, 2018 07:32 — forked from martinapugliese/ref_es_queries.md
Sample Elasticsearch queries in Python, as reference.

Collection of sample Elasticsearch queries

Use the Python client elasticsearch.

Connect to cluster (the client)

from elasticsearch import Elasticsearch

es_client = Elasticsearch() # local
@jimmytuc
jimmytuc / example_etl.py
Created April 8, 2019 00:57 — forked from dlstadther/example_etl.py
Example ETL Using Luigi
# import python core modules
import datetime
import logging
# import external modules
import pandas as pd
import requests
# import luigi modules
import luigi