This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Courtesy: @Fermatslibrary | |
| // Reference: https://twitter.com/fermatslibrary/status/1275066521450975234 | |
| // Copyright: Anand B Pillai @skeptichacker | |
| // LICENSE: MIT | |
| use std::env; | |
| use std::collections::HashMap; | |
| pub fn is_prime(n: u64) -> bool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| A simple get function which caches responses for a URL | |
| using a LFU cache | |
| """ | |
| import requests | |
| from collections import Counter | |
| class LFUCache(object): | |
| """ Least frequently used cache with caching done on SET """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ docli droplet --snapshot 163461766 | |
| βββββββββββββββββ€ββββββββββββββββββββββββββββββ | |
| β Fields β Values β | |
| βββββββββββββββββͺββββββββββββββββββββββββββββββ‘ | |
| β SnapShot Id β 53919120 β | |
| βββββββββββββββββΌββββββββββββββββββββββββββββββ€ | |
| β SnapShot Name β pfaas-sg-ps-1-1571760580915 β | |
| βββββββββββββββββΌββββββββββββββββββββββββββββββ€ | |
| β Distribution β Debian β | |
| βββββββββββββββββΌββββββββββββββββββββββββββββββ€ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ scrapy shell -s HTTPCACHE_ENABLED=True | |
| 2017-02-28 10:41:41 [scrapy.utils.log] INFO: Scrapy 1.3.2 started (bot: httpbin) | |
| (...) | |
| >>> from scrapy.utils.misc import load_object | |
| >>> storage = load_object(settings['HTTPCACHE_STORAGE'])(settings) | |
| >>> storage.cachedir | |
| '/home/paul/scrapy/httpbin/.scrapy/httpcache' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # For homogenous inputs, no assertion error | |
| def homogeneity(data): | |
| assert(len(dict(map(lambda x: (type(x), 1), data))) == 1) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| A Python program to light an LED digit on console | |
| Author: anandpillai@letterboxes.org | |
| """ | |
| import sys | |
| class LEDMatrix(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import threading | |
| import time | |
| class TTLDict(dict): | |
| """ A dictionary with keys having specific time to live """ | |
| def __init__(self, ttl=5): | |
| self._ttl = ttl | |
| # Internal key mapping keys of _d | |
| # to times of access |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| The State design pattern. | |
| In Python this is done dynamically by changing the __class__ attribute. | |
| Author : Anand B Pillai <anandpillai@letterboxes.org> | |
| License: Public Domain | |
| Ref: http://harkablog.com/dynamic-state-machines.html |
NewerOlder