Tech Tuneshttp://www.thetechnologyupdates.com
All about you need to know. Learn more. Act more.Mon, 01 Jan 2018 09:33:59 +0000en-UShourly1https://wordpress.org/?v=4.9.1http://www.thetechnologyupdates.com/wp-content/uploads/2016/01/cropped-favicon-32x32.pngTech Tuneshttp://www.thetechnologyupdates.com
3232thetechnologyupdates/BjRbhttps://feedburner.google.comHow to test multiple flag at once in Pythonhttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/uuFP1OAREeA/
http://www.thetechnologyupdates.com/test-multiple-flag-python/#respondMon, 01 Jan 2018 09:33:59 +0000http://www.thetechnologyupdates.com/?p=2433The post How to test multiple flag at once in Python appeared first on Tech Tunes.
]]>

]]>http://www.thetechnologyupdates.com/test-multiple-flag-python/feed/0http://www.thetechnologyupdates.com/test-multiple-flag-python/How to sort dict by key or value in Pythonhttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/b1dGbNYEilg/
http://www.thetechnologyupdates.com/sort-dict-key-value-python/#respondSun, 31 Dec 2017 06:43:41 +0000http://www.thetechnologyupdates.com/?p=2427The post How to sort dict by key or value in Python appeared first on Tech Tunes.
]]>

]]>http://www.thetechnologyupdates.com/python-trick-merge-dict-python/feed/0http://www.thetechnologyupdates.com/python-trick-merge-dict-python/How to avoid writing expensive code in Python with Memoizationhttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/Qdof0US5whw/
http://www.thetechnologyupdates.com/avoid-writing-expensive-code-python-memoization/#respondSat, 25 Nov 2017 16:21:00 +0000http://www.thetechnologyupdates.com/?p=2406Expensive Code: Ya, you read it right. In this article I’m going to brief on a way to speed up the Python programs and make expensive code cheaper with help of powerful caching technique called Memoization. Memoization is the effective technique that is used to speed up the computer programs. It memorize or cache the […]

]]>Expensive Code: Ya, you read it right. In this article I’m going to brief on a way to speed up the Python programs and make expensive code cheaper with help of powerful caching technique called Memoization.

Memoization is the effective technique that is used to speed up the computer programs. It memorize or cache the returning results of the given input to the function. So, when the same input or parameter is passed to the given function, the cached results are returned instead of performing the whole computation again. Hence, it is simple and effective technique.

The Flow of the Memoization implementation

Create a data structure to store the cache results

Each time when the function is called, compute the results and return it to data structure for caching

Now, for the similar input we will return the cached results instead of re-computing it again. Here, I will write memoization technique from scratch with the help of decorator. The decorator is a function that take another function as the parameter and returns function as the output. If you are not familiar with the decorator then it might be little confusing at first, I would recommend to learn a bit about decorator.

Here, I am using dict as the data structure for storing the cache results. Searching for the value in the dictionary is quick, hence it is effective for caching purpose. Here, when the decorated function is called, it will check for results in the cache for the given input. If found then it will return the cached results, else it will compute and store the results into the cache.

I will implement memoization on the Fibonacci series function. Let’s define the function that calculate the Fibonacci series.

Here, the computation Fibonacci will grow at the exponential rate. Hence, it is become pricey with growing results. Here, we will have execution time calculation with the help of timeit module in Python.

For computing the the 10th number in fibonacci, it took around 5 seconds on my machine. Now, let’s memoize this function and see the results. For the first run it would take a bit more but second run will have results as expected.

Let’s see how the results are stored in cache with the help of __closure__

WARNING: Here, we have the unbounded cache size which will keep eating your memory. And this is not the good idea, as it can raise out of memory bugs.

Inbuilt Function

In the above scenario we have written the decorator function from scratch. Now, lets implement the the memoization using the inbuilt function. And the inbuilt function will work far better then our manual function.

We will use the functools.lru_cache decorator for implementation of the memoization. lru_cache resides in the inbuilt functools package. Let’s try to implement our fibonacci function using functools.lru_cache. With this function we can also bound the cache memory with the help of maxsize parameter.

]]>http://www.thetechnologyupdates.com/avoid-writing-expensive-code-python-memoization/feed/0http://www.thetechnologyupdates.com/avoid-writing-expensive-code-python-memoization/AWS Lambda: Execute lambda asynchronously / parallelhttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/J7ODUkw2_vU/
http://www.thetechnologyupdates.com/aws-lambda-execute-lambda-asynchronously-parallel/#respondThu, 12 Oct 2017 17:41:15 +0000http://www.thetechnologyupdates.com/?p=2397AWS Lambda is a great micro-service to run code without managing servers with the scalable solution with few to thousands requests per second. Well, this great service comes with some limitations. One of the big limitation is the 5 Minutes execution time out window. Well, this limitation can be overcome by tweaks. Read more on […]

]]>AWS Lambda is a great micro-service to run code without managing servers with the scalable solution with few to thousands requests per second. Well, this great service comes with some limitations. One of the big limitation is the 5 Minutes execution time out window. Well, this limitation can be overcome by tweaks. Read more on how to increase lambda execution time

Well, the 5 minutes execution time limitation could be overcome by running the lambda asynchronously. But again it depends on the type of execution flow and what needs to achieve. I had a situation where I required to implement multiple implementation of lambda in parallel and implemented successfully. So, I thought to share.

If you have read my previous article then i have discussed about invoking recurrent lambdas. Well, we will use the same invoke code here. One can also invoke and run the same lambda function asynchronously or call the second lambda from one in parallel. Make sure you assign required permission to IAM role. We will use boto3 library here. Lets say, i want to run single lambda 5 times asynchronously.

The above code will invoke lambda asynchronously. Now, the same lambda is invoked 5 times and will run asynchronously. To check whether the lambda is running in parallel, you need to check the AWS CloudWatch logs. It will generate 5 log files for 5 parallel execution of lambda. This is how you can invoke parallel lambdas. Hope, this helps.

]]>http://www.thetechnologyupdates.com/aws-lambda-execute-lambda-asynchronously-parallel/feed/0http://www.thetechnologyupdates.com/aws-lambda-execute-lambda-asynchronously-parallel/AWS Lambda: Going Beyond 5 Minutes Executionhttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/fodSSvIJIpY/
http://www.thetechnologyupdates.com/aws-lambda-going-beyond-5-minutes-execution/#respondSat, 07 Oct 2017 18:32:46 +0000http://www.thetechnologyupdates.com/?p=2392AWS lambda is the great service to upload and run the code within the AWS infrastructure. I have been using Lambda since long. Let’s go through the quick overview on AWS Lambda. “AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when […]

]]>AWS lambda is the great service to upload and run the code within the AWS infrastructure. I have been using Lambda since long. Let’s go through the quick overview on AWS Lambda.

“AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second.” Learn more about lambdas on AWS Lambda docs

Well, It comes with certain limitations. Some of the limitations of the AWS services can be overcome by contacting AWS but some are default and it can’t be overcome even by contacting Amazon. The great AWS Lambda micro-service comes with limitation of 5 minutes execution and this limit is by design. (5 minutes time limitation)

Task/code that can execute within 5 minutes is good to go but what if the task execution goes beyond 5 minutes? There are various ways like SNS, SQS that can come to rescue to overcome this limitation. Apart from that i have implemented two approaches.

Write multiple lambdas

I had a scenario that process data and impose two logical script on that processed data (that goes beyond 5 minutes). To overcome this scenario, i wrote three lambda function that calls each after the execution. But, again there are two issues that needs to take care of

AWS Lambda keeps invoking other lambda after one minute

Managing three lambda function is a daunting task

To overcome constant invoking of one lambda function from another lambda function botocore comes handy. Set, socket read timeout to 300 seconds, so that it cannot keeps the connection open till 5 minutes. And set retry-config-lambda to zero. Below is the quick code.

Invoke recurrent lambdas

Instead of managing multiple lambdas, i created 3 class for each and hosted it on single lambda. So, all i have to manage the desired class. Here, i am invoking the same lambda back based on the time remaining using boto3 in python. And the good part is that you can manage all the class by passing the payload. Below is the quick code for self lambda invocation.

]]>http://www.thetechnologyupdates.com/python-mysql-database-access-video/feed/0http://www.thetechnologyupdates.com/python-mysql-database-access-video/Play hidden virtual fidget spinner on Googlehttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/rq0I5h3pm0o/
http://www.thetechnologyupdates.com/play-hidden-virtual-fidget-spinner-google/#respondWed, 28 Jun 2017 12:53:34 +0000http://www.thetechnologyupdates.com/?p=2379Google has always known for adding the hidden, secret and small games to it’s search engine. It allows you to play on the go and right on the search engine. As we know that a new toy “Fidget Spinner” is popular now a days. Google took no time to add a wonderful game to it’s […]

]]>Google has always known for adding the hidden, secret and small games to it’s search engine. It allows you to play on the go and right on the search engine. As we know that a new toy “Fidget Spinner” is popular now a days.

Google took no time to add a wonderful game to it’s search engine. To access this wonderful simulation game, you have to search the word “spinner” and make sure it is not the “fidget spinner” and it will return the wonderful virtual game.

I have it’s own mobile and desktop version and works good in Firefox and Chrome. The toy is exactly what you expect. Click on “SPIN” to keep fidget spinner in motion. Clicking continuously on the SPIN button will increase the rotation speed of the fidget. To stop, all you need to click on the fidget spinner.

Apart from the three-holed bearing fidget spinner there is a toggle button on the top right of the game. Toggle this button to switch to the virtual wheel of fortune. You can set the wheel from 2-20. Finally, a good way to pass a bad time.

]]>http://www.thetechnologyupdates.com/play-hidden-virtual-fidget-spinner-google/feed/0http://www.thetechnologyupdates.com/play-hidden-virtual-fidget-spinner-google/Explore these 5 links to know what Google knows about youhttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/PFENeBAFtkc/
http://www.thetechnologyupdates.com/explore-5-links-know-google-knows/#respondWed, 21 Jun 2017 13:19:02 +0000http://www.thetechnologyupdates.com/?p=2375Google, the most popular and widely used search engine around the world. We use it every now and then. Well, have you ever wondered what Google knows about you? Here are the 7 links or URLs that will show what Google knows about you. Your Full Google Search History Google records each and every search […]

]]>Google, the most popular and widely used search engine around the world. We use it every now and then. Well, have you ever wondered what Google knows about you? Here are the 7 links or URLs that will show what Google knows about you.

Your Full Google Search History

Google records each and every search made by you along with the clicks you do on ads. The full Google Search History information is available on:

Get information about the apps and extensions that are accessing your Google Data

The account activity page of your Google account provides you the list of applications and extensions that are using your data. Explore the permissions given to the desired apps and extension from here:

]]>http://www.thetechnologyupdates.com/explore-5-links-know-google-knows/feed/0http://www.thetechnologyupdates.com/explore-5-links-know-google-knows/Pair your fonts flawlessly with the help of machine learning using this sitehttp://feedproxy.google.com/~r/thetechnologyupdates/BjRb/~3/7wndL5n9AGk/
http://www.thetechnologyupdates.com/pair-fonts-flawlessly-help-machine-learning-using-site/#respondMon, 05 Jun 2017 14:41:17 +0000http://www.thetechnologyupdates.com/?p=2369This site can be a helping hand for the typography nerds and designers. It is quite tough for the typography geeks to mention the paring fonts. It’s not that easy. But thanks to this site that uses machine learning for generating the paring fonts. This project is started by the engineer-designer Jack Qiao known as […]

]]>This site can be a helping hand for the typography nerds and designers. It is quite tough for the typography geeks to mention the paring fonts. It’s not that easy. But thanks to this site that uses machine learning for generating the paring fonts.

This project is started by the engineer-designer Jack Qiao known as Fontjoy. It is backed with thousands of font, from which you can set around and you can set the primary choice while the site flips through suggestions. It allows you to lock the other two while site flips. The site creation extracts the vectors from font images and later vector arithmetic is used to compare different fonts.

“Through vector arithmetic we can isolate the features that represent visual concepts like serifs, obliqueness, and weight – or even more abstract concepts like legibility, kerning and color. One of the more interesting things we can do with font vectors is font pairing, or the problem of selecting fonts that work together in a design.” says Jack Qiao

Well, it is not likely to replace typography nerds in the near future. It is useful up-to some extent and you can have fun. Keep sharing. Stay tuned to Tech Tunes.