Skip to content

Instantly share code, notes, and snippets.

@lekhnath
lekhnath / convert_dpi.py
Created April 12, 2025 05:22 — forked from RobinXL/convert_dpi.py
Convert image with correct DPI for tesseract OCR purpose
from subprocess import Popen,PIPE, check_output
import os, sys
import tempfile
import uuid
import cv2
import pytesseract as pt
from PIL import Image
def convert_dpi(input_image):
path = tempfile.gettempdir()
@lekhnath
lekhnath / optimal-resize.py
Created April 1, 2025 20:16 — forked from rinogo/optimal-resize.py
Optimally resize an image so that its line height is approximately 32 pixels (Keywords: OpenCV, Tesseract, OCR)
#Optimally resize `img` according to the bounding boxes specified in `boxes` (which is simply the (pruned) results from `pytesseract.image_to_data()`).
#Tesseract performs optimally when capital letters are ~32px tall (https://groups.google.com/g/tesseract-ocr/c/Wdh_JJwnw94/m/24JHDYQbBQAJ). Smaller text obviously can't be OCR'd as accurately, but weirdly enough, larger text causes problems as well. So, this function uses the bounding boxes we've found and resizes the image so that the median line height should be ~32px.
def optimal_resize(img, boxes):
median_height = np.median(boxes["height"])
target_height = 32 #See https://groups.google.com/g/tesseract-ocr/c/Wdh_JJwnw94/m/24JHDYQbBQAJ
scale_factor = target_height / median_height
print("Scale factor: " + str(scale_factor))
#If the image is already within `skip_percentage` percent of the target size, just return the original image (it's better to skip resizing if we can)
skip_percentage = 0.07
@lekhnath
lekhnath / format-date.js
Created September 10, 2020 09:15 — forked from marlun78/format-date.js
A JavaScript date format inspired by the .NET framework
/**
* Date Format
* Copyright (c) 2011, marlun78
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83
*
* Format options inspired by the .NET framework's format.
* http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
*
* Non-formatting characters within the format string must be
* quoted (single (') or double (") quotes)! The same is true
@lekhnath
lekhnath / pre-receive-puppet
Created September 4, 2019 08:46 — forked from hartfordfive/pre-receive-puppet
Server-side pre-receive hook to validate puppet files.
#!/bin/bash
COMMAND='puppet parser validate'
TEMPDIR=`mktemp -d`
echo "### Attempting to validate puppet files... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive
oldrev=$1
newrev=$2
// ==UserScript==
// @name SaveFrom.net helper
// @namespace http://savefrom.net/
// @version 2.70
// @date 2014-07-12
// @author Magicbit, Inc
// @description Youtube Downloader: all in one script to get Vimeo, Facebook, Dailymotion videos for free
// @homepage http://savefrom.net/user.php?helper=userjs
// @icon http://savefrom.net/img/extension/icon_16.png
// @icon64 http://savefrom.net/img/extension/icon_64.png
@lekhnath
lekhnath / .babelrc
Created July 18, 2017 09:18 — forked from andrewmunro/.babelrc
Sequelize cli with ES6
{
"presets": ["es2015"],
"plugins": [
"add-module-exports"
],
}
@lekhnath
lekhnath / config.json
Created June 15, 2017 07:30
Cannot import / require json files in javascript projects with checkJs enabled
{
"name": "Lekhnath Rijal"
}
@lekhnath
lekhnath / .eslintrc
Created February 10, 2017 07:29 — forked from cletusw/.eslintrc
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@lekhnath
lekhnath / app.js
Last active August 6, 2017 08:29
BS to AD converter and vice versa
var BS_MONTHS_FULL_NE = ['वैशाख', 'जेठ', 'असार', 'साउन', 'भदौ', 'असोज', 'कात्तिक', 'मंसिर', 'पुष', 'माघ', 'फागुन', 'चैत'];
var BS_DAYS_FULL_NE = ['आईतबार', 'सोमबार', 'मंगलबार', 'बुधबार', 'बिहीबार', 'शुक्रबार', 'शनिबार'];
function convertBs2Ad(e){
e.preventDefault();
var form, bsDate, adDate;
try {
@lekhnath
lekhnath / introrx.md
Created April 28, 2016 11:08 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing