Skip to content

Instantly share code, notes, and snippets.

View siddht5's full-sized avatar

siddht5

  • Earth
View GitHub Profile
@siddht5
siddht5 / test.py
Created April 20, 2018 05:43
loop
fr1 = open('check', "r")
fr2=open('test',"r")
_kfile=[]
for a in fr1:
_kfile.append(a)
for b in fr2:
_kfile.append(b)
fo = open('main', "w")
fo.write(str(_kfile))
fo.close()
@siddht5
siddht5 / google_drive_util.py
Created December 30, 2017 09:47 — forked from macieksk/google_drive_util.py
A simple Python module to upload files to Google Drive file upload. Needs a file 'client_secrets.json' in the directory . The file can be obtained from https://console.developers.google.com/ -- under APIs&Auth/Credentials/Create Client ID for native application
## Simple Python module to upload files to Google Drive
# Needs a file 'client_secrets.json' in the directory
# The file can be obtained from https://console.developers.google.com/
# under APIs&Auth/Credentials/Create Client ID for native application
# To test usage:
# import google_drive_util
# google_drive_util.login()
# google_drive_util.test()
@siddht5
siddht5 / unicode_csv.py
Created December 25, 2017 19:33 — forked from hvtuananh/unicode_csv.py
Python Unicode CSV Reader/Writer (fix writerow problem in Python docs)
#http://docs.python.org/2.7/library/csv.html
import csv, codecs, cStringIO
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
@siddht5
siddht5 / test.py
Created December 23, 2017 19:24 — forked from christianroman/test.py
Bypass Captcha using 10 lines of code with Python, OpenCV & Tesseract OCR engine
import cv2.cv as cv
import tesseract
gray = cv.LoadImage('captcha.jpeg', cv.CV_LOAD_IMAGE_GRAYSCALE)
cv.Threshold(gray, gray, 231, 255, cv.CV_THRESH_BINARY)
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
api.SetPageSegMode(tesseract.PSM_SINGLE_WORD)
tesseract.SetCvImage(gray,api)
print api.GetUTF8Text()
@siddht5
siddht5 / convert_csv_to_json
Created December 22, 2017 17:12 — forked from d4rk8l1tz/convert_csv_to_json
Python : Convert CSV to JSON (line by line)
def convertCSVtoJSON(input): #pass the name of the input csv file
f = open(input, 'r')
j = open('.tempJSON', 'w')
fieldnames = ("field1,field2,field3")
reader = csv.DictReader(f, fieldnames)
for row in reader:
json.dump(row, j)
j.write('\n')
f.close()
j.close()
Working with AsyncTasks on Android
from category Android
Introduction
Developing Android applications is a lot of fun because it offers a lot of possibilities to implement one's own ideas. Frequently i have to use AsyncTasks to do heavy work aside the ui thread. In the following i give a quick overview on AsyncTasks and provide some code snippets that might be useful for everyday development with Android regarding the use of AsyncTasks.
Lifecycle
An AsyncTask in Android is used to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers (more information). The structure follows call onPreExecute() for preparation, doInBackground() for doing the main task and return its result finally to the onPostExecute() method. Optional you can implement the onProgressUpdate() method e.g. to show a progressbar.
The following example can be used as template for an AsyncTask.
private class MyTask extends AsyncTask<Object, Void, Object> {
@siddht5
siddht5 / get_barcode_from_image.js
Created December 18, 2017 14:50 — forked from tbtlr/get_barcode_from_image.js
Barcode recognition with JavaScript - Demo: http://bit.ly/djvUoy
/*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*/
(function(){
var UPC_SET = {
"3211": '0',
"2221": '1',
"2122": '2',
@siddht5
siddht5 / detect_color.py
Created December 14, 2017 06:54
color_detection
# USAGE
# python detect_color.py --[image] ; example "python detect_color.py --123.png"
# import the necessary packages
import numpy as np
import argparse
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
@siddht5
siddht5 / face_1.py
Last active December 13, 2017 15:46
face_detect
import cv2
import sys
# Get user supplied values
imagePath = sys.argv[1]
cascPath = "haarcascade_frontalface_default.xml"
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
@siddht5
siddht5 / csv-to-json.js
Created December 12, 2017 09:44 — forked from iwek/csv-to-json.js
CSV to JSON Conversion in JavaScript
//var csv is the CSV file with headers
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){