Skip to content

Instantly share code, notes, and snippets.

View pythonhacker's full-sized avatar
πŸ’­
Full Reset

Anand B Pillai pythonhacker

πŸ’­
Full Reset
View GitHub Profile
@pythonhacker
pythonhacker / prime_anagrams.rs
Last active June 25, 2020 06:19
@fermatslibrary - Anagram finder implemented using Prime Numbers in Rust
// 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 {
"""
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 """
@pythonhacker
pythonhacker / docli.log
Last active November 6, 2019 07:29
Error when running docli
$ docli droplet --snapshot 163461766
╒═══════════════╀═════════════════════════════╕
β”‚ Fields β”‚ Values β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ═════════════════════════════║
β”‚ SnapShot Id β”‚ 53919120 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ SnapShot Name β”‚ pfaas-sg-ps-1-1571760580915 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Distribution β”‚ Debian β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
@pythonhacker
pythonhacker / scrapy_settings.txt
Created February 13, 2019 10:40
Find Scrapy HTTP cache directory
$ 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'
@pythonhacker
pythonhacker / homogeneity.py
Created January 16, 2018 13:28
Test homogeneity of a Python data structure using a one liner
# For homogenous inputs, no assertion error
def homogeneity(data):
assert(len(dict(map(lambda x: (type(x), 1), data))) == 1)
@pythonhacker
pythonhacker / led_digit.py
Created February 28, 2017 12:47
Light an LED digit on the console using Python
"""
A Python program to light an LED digit on console
Author: anandpillai@letterboxes.org
"""
import sys
class LEDMatrix(object):
@pythonhacker
pythonhacker / ttldict.py
Created October 12, 2016 05:54
A Python dictionary type with keys having specific time to live (TTL)
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
@pythonhacker
pythonhacker / state.py
Last active June 22, 2022 07:01
Example of State Pattern in Python implementing showing a minimal State Machine
"""
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