Skip to content

Instantly share code, notes, and snippets.

View ichim-david's full-sized avatar

David Ichim ichim-david

  • Romania
View GitHub Profile
@ichim-david
ichim-david / data.json
Created May 2, 2017 12:00
Cache a whole SPA website and its assets via app cache, service workers and localstorage
{
"secret-message": "hello"
}
@ichim-david
ichim-david / express-server-side-rendering.md
Created October 4, 2017 06:01 — forked from joepie91/express-server-side-rendering.md
Rendering pages server-side with Express (and Pug)

Terminology

  • View: Also called a "template", a file that contains markup (like HTML) and optionally additional instructions on how to generate snippets of HTML, such as text interpolation, loops, conditionals, includes, and so on.
  • View engine: Also called a "template library" or "templater", ie. a library that implements view functionality, and potentially also a custom language for specifying it (like Pug does).
  • HTML templater: A template library that's designed specifically for generating HTML. It understands document structure and thus can provide useful advanced tools like mixins, as well as more secure output escaping (since it can determine the right escaping approach from the context in which a value is used), but it also means that the templater is not useful for anything other than HTML.
  • String-based templater: A template library that implements templating logic, but that has no understanding of the content it is generating - it simply concatenates together strings, potenti
@ichim-david
ichim-david / app-output.txt
Created October 5, 2017 15:42 — forked from cpsubrian/app-output.txt
nconf with multiple files
$ node app.js
My specific title
green
undefined
@ichim-david
ichim-david / update_git_repos.sh
Created February 13, 2018 09:54 — forked from douglas/update_git_repos.sh
Update all git repositories under a base directory
#!/bin/bash
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo "\n\033[1mPulling in latest changes for all repositories...\033[0m\n"
# Find all git repositories and update it to the master latest revision
for i in $(find . -name ".git" | cut -c 3-); do
@ichim-david
ichim-david / casperjs-delete-harvesting-sources.js
Created December 20, 2018 18:39 — forked from michimau/casperjs-delete-harvesting-sources.js
deleting undesired harvest sources of sds. usage: casperjs test casperjs-delete-harvesting-sources.js
var x = require('casper').selectXPath;
casper.options.viewportSize = {width: 1920, height: 982};
casper.on('page.error', function(msg, trace) {
this.echo('Error: ' + msg, 'ERROR');
for(var i=0; i<trace.length; i++) {
var step = trace[i];
this.echo(' ' + step.file + ' (line ' + step.line + ')', 'ERROR');
}
});
casper.test.begin('Resurrectio test', function(test) {
@ichim-david
ichim-david / CrashCourseInCrUX.md
Created April 3, 2019 20:14 — forked from rviscomi/CrashCourseInCrUX.md
"Crash Course in CrUX" for the PerfMatters conference, April 2019
@ichim-david
ichim-david / upgrades.py
Created April 4, 2019 14:46 — forked from thet/upgrades.py
Plone / Zope Component Architecture: Unregister all broken persistent utilities
# -*- coding: utf-8 -*-
from zope.component.hooks import getSite
import logging
log = logging.getLogger(__name__)
def unregister_broken_persistent_components(context):
portal = getSite()
sm = portal.getSiteManager()
@ichim-david
ichim-david / README.md
Created May 10, 2019 11:31 — 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

@ichim-david
ichim-david / conftest.py
Created May 10, 2019 11:37 — forked from MatthewWilkes/conftest.py
Pyramid functional testing example
from contextlib import contextmanager
import tempfile
from unittest import mock
import factory
import pytest
from betterevidence import models
import logging
import plone.api as api
logger = logging.getLogger(__name__)
def _update_brain(brains, index, column_index, value):
""" Update the brain directly, modifying only the target field
This is much faster than update_metadata=True, as that rebuilds the
entire brain, calling all indexed attributes.