Skip to main content

Posts

test embedded

  https://www.youtube.com/watch?v=7HDO1p3VdYg

using python tornado skeleton

import time import tornado.ioloop import tornado.web from tornado import gen, concurrent import json class MainHandler ( tornado . web . RequestHandler ): # @gen.coroutine # def get(self): # l = ['Ram', 'Shyam', 'Sita', 'Lakshman'] # v = random.choice(l) # yield self.write("Hello, world --> " + v) @gen.coroutine # @concurrent.run_on_executor(executor='_thread_pool') def post ( self ): print ( self ) # req_data = (json.loads(self.request.body)) print ( self .request.body) req_data = (json.loads( self .request.body.decode( 'utf-8' ))) # # print("inside the post request") channelID = req_data[ "channelId" ] print ( "channelid :" + channelID) self .set_header( "Content-Type" , "text/plain" ) yield self .write(channelID) def make_app (): return to...

remove unwanted files from git of gitignore

It is as simple as  Website link :  https://stackoverflow.com/questions/46273032/is-there-a-way-to-remove-all-ignored-files-from-a-git-repo/46273201 git clean -dfX git-clean - Remove untracked files from the working tree -d  for removing directories -f  remove forcefully -n  Don’t actually remove anything, just show what would be done. -X  Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.

remove unwanted file from git repo after using git add . and gitignore

# # I just ran into this after initializing a Visual Studio project _before_ adding a .gitignore file (like an idiot). # # I felt real dumb commiting a bunch of files I didn't need to, so the commands below should do the trick. The first two commands # # came from the second answer on this post: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files # See the unwanted files: git ls-files -ci --exclude-standard # Remove the unwanted files: git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached # Commit changes git commit -am " Removed unwanted files marked in .gitignore " # Push reference : https://gist.github.com/jeffjohnson9046/80bc182db7ae2f4a6150

subprocess

Python subprocess running ffmpeg in the python subprocess if there is some error .. mark the shell=True process = subprocess.Popen( command , stdout =subprocess.PIPE , shell = True )

example of threading in python

# Python program to illustrate the concept # of threading import threading import os def task1 (): print ( "Task 1 assigned to thread: {}" .format(threading.current_thread().name)) print ( "ID of process running task 1: {}" .format(os.getpid())) for i in range ( 200 ): print ( "task1 : " + str (i)) def task2 (): print ( "Task 2 assigned to thread: {}" .format(threading.current_thread().name)) print ( "ID of process running task 2: {}" .format(os.getpid())) for i in range ( 200 ): print ( "task2 : " + str (i)) if __name__ == "__main__" : # print ID of current process print ( "ID of process running main program: {}" .format(os.getpid())) # print name of main thread print ( "Main thread name: {}" .format(threading.main_thread().name)) # creating threads t1 = threa...

youtube-dl download using python in a specific folder and of a particular quality

import  subprocess import  tempfile import  os import  youtube_dl import  time class   MyLogger ( object ):      def   debug ( self ,  msg ):          pass      def   warning ( self ,  msg ):          pass      def   error ( self ,  msg ):          print (msg) def   my_hook ( d ):      if  d[ 'status' ] ==  'finished' :          print ( 'Done downloading, now converting ...' ) ydl_opts = {           'outtmpl' :  './temp/ZCL5.mp4' ,      'logger' : MyLogger(),      'progress_hooks' : [my_hook],  ...

asyncio concurrent task in loop in python 3.7

import asyncio import time async def say_after(delay, what):     print(f"Req time at {time.strftime('%X')} for "+ what)     await asyncio.sleep(delay)     # print(what)     print(f"Return time at {time.strftime('%X')} for "+ what + " delay = "+ str(delay))     return ("hero , delay = " + str(delay)+ " value = "+ what ) async def main():     # task1 = asyncio.create_task(     #     say_after(1, 'hello'))     #     # task2 = asyncio.create_task(     #     say_after(2, 'world'))     print(f"started at {time.strftime('%X')}")     tasks = []     loop: AbstractEventLoop = asyncio.get_event_loop()     for i in range(5):         tasks.append(asyncio.create_task(         say_after(i+1, 'pila')         ))         # print( val ...

multiprocessing with asyncio in python sample program

import asyncio import time async def say_after(delay, what):     await asyncio.sleep(delay)     print(what)     return ("hero" + str(delay)) async def main():     task1 = asyncio.create_task(         say_after(1, 'hello'))     task2 = asyncio.create_task(         say_after(2, 'world'))     print(f"started at {time.strftime('%X')}")     # Wait until both tasks are completed (should take     # around 2 seconds.)     print(await task1)     print(await task2)     print(f"finished at {time.strftime('%X')}") asyncio.run(main())

highlight text in elasticsearch result

Example PUT test_index/_doc/doc1 {   "content" : "For you I'm only a fox like a hundred thousand other foxes. But if you tame me, we'll need each other. You'll be the only boy in the world for me. I'll be the only fox in the world for you." } GET test_index/_search {     "query": {         "match_phrase" : {"content" : "only fox"}     },     "highlight": {         "type" : "unified",         "number_of_fragments" : 3,         "fields": {             "content": {}         }     } } ---------------------- for deepdive "highlight": {     "fields": {       "script": {}     }   }