Skip to content

Instantly share code, notes, and snippets.

View t27's full-sized avatar

Tarang Shah t27

View GitHub Profile
@t27
t27 / OpenCV-Tesseract.md
Last active March 9, 2021 21:42
Converting OpenCV Mat to Tesseract Compatible formats

I was primarily using the JavaCPP presets for OpenCV(JavaCV) and Tesseract

But I also found some references for C++

Here's what works for C++

#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>    
#include 
import time
from threading import Thread
def myfunc(i):
print "sleeping 5 sec from thread %d" % i
time.sleep(5)
print "finished sleeping from thread %d" % i
for i in range(10):
t = Thread(target=myfunc, args=(i,))
@t27
t27 / runner.py
Created June 13, 2017 10:02
Run a command continously (Reloads a command/program if it crashes)
#!/usr/bin/env python
import signal
import sys
import os
import subprocess
process = 0
if len(sys.argv[:])<2:
print "USAGE: python runner.py \"<your execution statement>\" \nQuotes are only necessary of you want to do redirection or something like that"
else:
@t27
t27 / docker.sh
Created February 3, 2018 20:07
Virtual Linux docker for compiling apps etc.
# run this command to create the docker container
docker run \
--name ubuntuDev \ #containername
-e HOST_IP=$(ifconfig en0 | awk '/ *inet /{print $2}') \ #map the system and container Its, helpful for dev
-v ~/Code:/Code \ #mount the local directory on the container
-t -i \
ubuntu:14.04 /bin/bash
# This created a container called ubuntuDev using the 'ubuntu:14.04' image from docker hub and runs bash interactively.
# -e ensures your networks are mapped correctly
@t27
t27 / git-tag-update.sh
Created February 3, 2018 20:12
Move a git tag on an older commit to a newer commit
#!/bin/bash
# usage
# > ./git-tag-update.sh <tagname>
TAGNAME=$1
git push --delete origin $TAGNAME # Deletes old tag from the server
git tag --delete $TAGNAME # Delete the old tag from local branch
git tag $TAGNAME # add the tag to the latest commit
git push --tags # persist tags to the server
@t27
t27 / external-img-to-inlinebase64.js
Last active February 3, 2018 20:17
Converts all the external images in a webpage to inline base64 format - which makes it easier to then "Save" the whole document without worrying about missing images
// Convert all img tags to use base64 src
function toDataUrl(url, elem) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
//callback(reader.result);
elem.src = reader.result
}
reader.readAsDataURL(xhr.response);
@t27
t27 / render_json_jupyter_collapsible.py
Last active February 5, 2024 18:40
Render JSON as a collapsible field in jupyter notebooks - Updated - Also includes instructions for interleaving with print statements
## Add this to the first block in your note book
import uuid
from IPython.core.display import display, HTML
import json
class RenderJSON(object):
def __init__(self, json_data):
if isinstance(json_data, dict):
self.json_str = json.dumps(json_data)
@t27
t27 / screen-commands.sh
Created July 8, 2018 15:06
Generally useful GNU Screen commands - Especially on cloud compute instances
## Start/Resume a named screen
# -L enables logging
# -d detaches the screen if there is an existing screen attached
# -r resumes the the screen if it exists
screen -d -r -L <sessName>
## See all open screens
screen -ls
## To detach from a screen
@t27
t27 / parallel_python.py
Last active April 21, 2020 12:45
Script to show sample code(boilerplate) for concurrent execution using concurrent.futures.ThreadPoolExecutor in python 3 (mainly IO operations like network calls, ie. HTTP etc)
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
Thread_pool = ThreadPoolExecutor(6) # can change 6 to any number
def sample_sum_func(arg1,arg2):
print("start",arg1,arg2)
time.sleep(2)
print("end",arg1,arg2)
@t27
t27 / index.html
Last active August 24, 2018 05:10 — forked from d3noob/.block
Sankey from csv with d3.js
<!DOCTYPE html>
<meta charset="utf-8">
<title>SANKEY Experiment</title>
<style>
.node rect {
cursor: move;
fill-opacity: .9;
shape-rendering: crispEdges;
}