This is a autopost bolg frinds we are trying to all latest sports,news,all new update provide for you
Wednesday, November 9, 2022
Show HN: Generic dual-paradigm hooking mechanism https://ift.tt/ER8p0wT
Show HN: Generic dual-paradigm hooking mechanism Hi HN ! I am Alex, a tech enthusiast, I'm excited to show you a major iteration of my library for performing hooking in Python. I redesigned the whole project because it didn't not cover all my needs. I'm happy with the current iteration that I've written tests for and look forward to spending weeks and months using it in my projects. Python has a concept called Decorator [1] which is a function that takes another function and extends the behavior. In the following script, the timeit decorator is used to measure the execution time of the heavy_computation function: import time from functools import wraps def timeit(text): def deco(target): @wraps(target) def wrapper(*args, **kwargs): # execute and measure the target run time start_time = time.perf_counter() result = target(*args, **kwargs) total_time = time.perf_counter() - start_time # print elapsed time print(text.format(total=total_time)) return result return wrapper return deco @timeit(text="Done in {total:.3f} seconds !") def heavy_computation(a, b): time.sleep(2) # doing some heavy computation ! return a*b if __name__ == "__main__": result = heavy_computation(6, 9) print("Result:", result) Output: $ python -m test Done in 2.001 seconds ! Result: 54 Besides benchmarking, there are many other cool things that can be done with the Python decorator. For example, the Flask [2] and Bottle [3] web frameworks implement routing with decorators. While decorators are cool, it's worth mentioning that using a decorator is much more intuitive than writing its code. The code is entirely different depending on whether the decorator takes arguments or not. The following code performs the same task as the previous one, except it is more clear and intuitive: import time from hooking import on_enter def timeit(context, *args, **kwargs): # execute and measure the target run time start_time = time.perf_counter() context.result = context.target(*args, **kwargs) total_time = time.perf_counter() - start_time # print elapsed time text = context.config.get("text") # get 'text' from config data print(text.format(total=total_time)) context.target = None @on_enter(timeit, text="Done in {total:.3f} seconds !") def heavy_computation(a, b): time.sleep(2) # doing some heavy computation ! return a*b if __name__ == "__main__": result = heavy_computation(6, 9) print("Result:", result) Output: $ python -m test Done in 2.001 seconds ! Result: 54 The Hooking library used in the code above uses Python decorators to wrap, augment, and override functions and methods. It is a generic hooking [4] mechanism which is perfect for creating a plug-in mechanism for a project, performing benchmarking and debugging, implementing routing in a web framework, et cetera. Also, it is a dual paradigm hooking mechanism since it supports tight and loose coupling [5]. The previous code uses the tight coupling paradigm, that's why the timeit hook is directly tied to the target function. In loose coupling paradigm, targets functions and methods are tagged using a decorator, and hooks are bound to these tags. So when a target is called, the bound hooks are executed upstream or downstream. This paradigm is served by a class designed for pragmatic access via class methods [6]. This class can be easily subclassed to group tags by theme for example. Here is an example of the loose coupling paradigm: import time from hooking import H @H.tag def heavy_computation(a, b): print("heavy computation...") time.sleep(2) # doing some heavy computation ! return a*b def upstream_hook(context, *args, **kwargs): print("upstream hook...") def downstream_hook(context, *args, **kwargs): print("downstream hook...") # bind upstream_hook and downstream_hook to the "heavy_computation" tag H.wrap("heavy_computation", upstream_hook, downstream_hook) if __name__ == "__main__": result = heavy_computation(6, 9) print("Result:", result) Output: $ python -m test upstream hook... heavy computation... downstream hook... Result: 54 This library is available on PyPI and you can play with the examples [7] which are on the project's README. I would like to know what you think [8] of this project. Your questions, suggestions and criticisms are welcome ! [1] https://ift.tt/pAH3xzD [2] https://ift.tt/TpVkMb2 [3] https://ift.tt/ST6sPoY [4] https://ift.tt/fOoPCaD [5] https://ift.tt/OUdpxLY... [6] https://ift.tt/TMsqaAE [7] https://ift.tt/8syOiWn [8] https://ift.tt/gRYKOc5 https://ift.tt/3L5Se1c November 9, 2022 at 06:40PM
भास्कर अपडेट्स:गुजरात में विधानसभा चुनाव से पहले कांग्रेस को झटका, विधायक भावेश कटारा ने इस्तीफा दे दिया

via देश | दैनिक भास्कर https://ift.tt/Mamklrs
Show HN: Unblob – accurate, fast, and easy-to-use extraction suite https://ift.tt/cSAsLVn
Show HN: Unblob – accurate, fast, and easy-to-use extraction suite https://unblob.org/ November 10, 2022 at 12:16AM
Tuesday, November 8, 2022
Show HN: Helping laid-off people find their next job https://ift.tt/sWB4v2D
Show HN: Helping laid-off people find their next job https://ift.tt/FUGkZ2a November 8, 2022 at 10:42PM
भास्कर अपडेट्स:केंद्रीय नागरिक उड्डयन मंत्री ज्योतिरादित्य सिंधिया कोरोना पॉजिटिव, खुद ट्वीट कर दी जानकारी

via देश | दैनिक भास्कर https://ift.tt/T0RtjcG
प्रधानमंत्री मोदी आज हिमाचल में:कांगड़ा के शाहपुर और हमीरपुर के सुजानपुर में करेंगे जनसभाएं; सुरक्षा के दृष्टिगत पैराग्लाइडिंग, ड्रोन, हेलिकॉप्टर उड़ाने पर प्रतिबंध

via देश | दैनिक भास्कर https://ift.tt/nQMhsdK
Show HN: Pet Portrait AI – Custom Pet Portraits https://ift.tt/sHl9x7S
Show HN: Pet Portrait AI – Custom Pet Portraits https://petportrait.ai/ November 9, 2022 at 12:26AM
बेटी-भतीजे और भाई समेत कार लेकर नहर में कूदा:मौत से पहले वीडियो बनाया, पत्नी पर लगाए अवैध संबंध के आरोप

via देश | दैनिक भास्कर https://ift.tt/Cj1pnEu
Show HN: TwitterBreak.app – quickly find/follow your Twitter follows on Mastodon https://ift.tt/ocCKyjU
Show HN: TwitterBreak.app – quickly find/follow your Twitter follows on Mastodon Built this in my spare time over the last couple days to help people explore Mastodon with some friendly faces. Feedback welcome! Early feedback: Random errors connecting to twitter or mastodon instances. - working on this. https://ift.tt/ikNeIzM November 8, 2022 at 11:37PM
Monday, November 7, 2022
आर्थिक आरक्षण:आख़िर सुप्रीम कोर्ट ने ग़रीब सवर्णों की सुन ली, अब 50% के पार होगा आरक्षण

via देश | दैनिक भास्कर https://ift.tt/BIfzCVD
सूचना के अधिकार का तिरस्कार:हर मिनट में 11 RTI, सूचना देने से मना करने के केस निपटाने में 24 साल तक लग रहे

via देश | दैनिक भास्कर https://ift.tt/SvLrXb3
Show HN: Automated unique exam creator and correction https://news.ycombinator.com/item?id=33512779
Show HN: Automated unique exam creator and correction https://ift.tt/OMrZ8LI November 8, 2022 at 02:59AM
Show HN: Text-to-Figma https://ift.tt/SuoWCgU
Show HN: Text-to-Figma Hey HN! I've made a NLUI for Figma. This is based on GPT-3 (for generating components & schemas) and Dall-E 2 (for image generation); it's remarkably flexible already and there's plenty of room to expand. One of the more noteworthy features is the ability to edit existing designs instead of just generating things from scratch - we accomplish this by training it on pairs of (before, after) designs in Figma with a description of what changed, and it learns to output the diff based on the description of the change. Let me know what you think! https://twitter.com/mathemagic1an/status/1589657222094934016 November 8, 2022 at 02:00AM
भास्कर अपडेट्स:महाराष्ट्र के रायगढ़ में रेत से भरा डंपर ऑटो रिक्शा पर पलटा, 4 की मौत

via देश | दैनिक भास्कर https://ift.tt/LXEScKD
Show HN: Open-source and real-time orchestrator for distributed architectures https://ift.tt/Ufkq8cs
Show HN: Open-source and real-time orchestrator for distributed architectures https://ift.tt/83hyfNJ November 7, 2022 at 10:13PM
Sunday, November 6, 2022
हरियाणा में राजनीतिक घरानों का सियासी मुकाबला:इस बार कुलदीप बिश्नोई की भूपेंद्र हुड्डा को मात; 17 साल से जारी 'सियासी चौधर' की लड़ाई

via देश | दैनिक भास्कर https://ift.tt/rZRYbLe
हरियाणा में हिसार लोकसभा सीट 'कांग्रेस मुक्त':आदमपुर हार के बाद 9 विधानसभा सीटों में अब 5 पर BJP, 4 पर जजपा का कब्जा

via देश | दैनिक भास्कर https://ift.tt/fGROLl5
वर्ल्ड कप सेमीफाइनल में भारत-पाकिस्तान:जीते तो 15 साल बाद फाइनल में भिड़ेंगे; तिरुपति मंदिर के पास 16 हजार करोड़ कैश

via देश | दैनिक भास्कर https://ift.tt/kFJt4dr
गुलाम नबी आजाद ने कांग्रेस की तारीफ में कसीदे पढ़े:बोले- गुजरात-हिमाचल चुनाव में BJP को सिर्फ कांग्रेस ही टक्कर दे सकती है

via देश | दैनिक भास्कर https://ift.tt/JqI7GA1
वेब-म्यूजिक सीरीज के लिए कश्मीर पसंदीदा जगह:शूटिंग के लिए ग्रामीण इलाकों पर फोकस; मुख्य भूमिका में भी स्थानीय कलाकार

via देश | दैनिक भास्कर https://ift.tt/uzgV7Qo
Subscribe to:
Posts (Atom)
Show HN: Free OSS transcription app I made and found it's faster than wispr flow https://ift.tt/2h9d6Kn
Show HN: Free OSS transcription app I made and found it's faster than wispr flow title doesn't let nuance, ofc it's not the app ...
-
Show HN: A directory of 800 free APIs, no auth required Explore reliable free APIs for developers — ideal for web and software development, ...
-
Show HN: I built Dirac, Hash Anchored AST native coding agent, costs -64.8 pct Fully open source, a hard fork of cline. Full evals on the gi...
-
Show HN: I built a FOSS tool to run your Steam games in the Cloud I wanted to play my Steam games but my aging PC couldn’t keep up, so I bui...