Skip to content

Instantly share code, notes, and snippets.

@joyrexus
joyrexus / README.md
Last active June 8, 2023 07:45
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing

@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active March 24, 2025 20:20
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@carlhoerberg
carlhoerberg / reconnect.js
Created May 13, 2015 14:45
How to build reconnect logic for amqplib
var amqp = require('amqplib/callback_api');
// if the connection is closed or fails to be established at all, we will reconnect
var amqpConn = null;
function start() {
amqp.connect(process.env.CLOUDAMQP_URL + "?heartbeat=60", function(err, conn) {
if (err) {
console.error("[AMQP]", err.message);
return setTimeout(start, 1000);
}
@alexaleluia12
alexaleluia12 / cleaner.sh
Last active December 30, 2015 12:33
Exclude executable files but not .sh files nor directories
#!/bin/bash
# to get the list of files to exclude
# ls -al | grep ^- | egrep "^[a-z-]+x " | grep -v .sh$ | cut -d' ' -f 9 > arq_exc
# then
for i in $(cat arq_exc); do
rm - $i
done
@alexaleluia12
alexaleluia12 / file.cpp
Created December 30, 2015 13:08
error: cannot convert ‘std::vector<float*>’ to ‘float*’ in assignment
// I want to share a tricky thing that happened with me
// * I was programming in C style using feature of C++ (on g++)
// I have this structure
typedef struct {
vector<float *> * lst_vertices;
vector<int *> * lst_faces;
float referencia[3];// o ponto sobre o qual vai ser realizadas as transformacoes
} Obj3d;
@alexaleluia12
alexaleluia12 / finditer-version.py
Last active June 23, 2021 22:59
token / tokenizer / lexico / tokenizing in python
# Can I use finditer ?
# Yes
# ...
def generate_tokens(pat, text):
scanner = pat.finditer(text)
for i in scanner:
yield Token(i.lastgroup, i.group())
@alexaleluia12
alexaleluia12 / compiler.py
Created January 10, 2016 21:30
compiler / compilador / sintatico / in python
# font
# http://chimera.labs.oreilly.com/books/1230000000393/ch02.html#_writing_a_simple_recursive_descent_parser
"""
grammar
expr ::= expr + term
| expr - term
| term
@dannguyen
dannguyen / README.md
Last active September 10, 2024 19:41
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

FROM python:2.7-alpine
MAINTAINER Nick Janetakis <[email protected]>
ENV INSTALL_PATH /bsawf
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN apk add --no-cache --virtual .build-deps \