Skip to content

Instantly share code, notes, and snippets.

View asimihsan's full-sized avatar

Asim Ihsan asimihsan

View GitHub Profile
@asimihsan
asimihsan / notes.md
Last active April 3, 2024 16:00
Dependency Injector example

Step 1: Define Service Classes and Interfaces

# services.py
import requests

class CsvContentFetcher:
    def fetch(self, csv_uri: str) -> str:
        # Depending on the scheme in `csv_uri`, fetch the content from S3 or local file
        if csv_uri.startswith("s3://"):
2023-11-23 16:06:00
2023-11-23 16:06:00 LocalStack version: 3.0.0
2023-11-23 16:06:00 LocalStack Docker container id: ed4bb0a693d4
2023-11-23 16:06:00 LocalStack build date: 2023-11-16
2023-11-23 16:06:00 LocalStack build git hash: 6dd3f3d
2023-11-23 16:06:00
2023-11-23 16:06:00 2023-11-23T21:06:00.514 INFO --- [ MainThread] l.bootstrap.licensingv2 : Successfully activated cached license license_7e180b27-97b2-498e-854e-c79669e857f2:pro from /var/lib/localstack/cache/license.json 🔑✅
2023-11-23 16:06:00 Localstack returning with exit code 55. Reason:
2023-11-23 16:06:00 ===============================================
2023-11-23 16:06:00 License activation failed! 🔑❌
@asimihsan
asimihsan / gist:2266588
Created March 31, 2012 16:35
python retry decorator
import pymongo.errors
# Retry decorator with exponential backoff
def retry(tries=5, delay=0.1, backoff=2):
"""Retries a function or method until it returns True.
delay sets the initial delay in seconds, and backoff sets the factor by which
the delay should lengthen after each failure. backoff must be greater than 1,
or else it isn't really a backoff. tries must be at least 0, and delay
greater than 0.
@asimihsan
asimihsan / memory-usage.jira
Created July 24, 2014 16:38
Memory usage on Linux systems
Memory usage on Linux systems
(TODO I'm going to edit and refactor this article a bit)
h2. tl;dr
* The Proportional Set Size (PSS) of a process is the count of pages it
has in memory, where each page is divided by the number of processes
sharing it.
* The Unique Set Size (USS) of a process is the count of unshared pages.
tee $HOME/setup_mac_inner.sh <<'EOF'
#!/usr/bin/env bash
# See: https://github.com/thoughtbot/laptop/blob/master/mac
set -euo pipefail
fancy_echo() {
local fmt="$1"; shift
PROJECT_NAME=project-name
cargo install cargo-edit --features vendored-openssl,vendored-libgit2
cargo install cargo-deny
mkdir "$PROJECT_NAME"
cd "$PROJECT_NAME"
git init .
cat << EOF > Cargo.toml
[workspace]
@asimihsan
asimihsan / pm1.als
Created January 20, 2022 05:49
Formal modeling as a design tool
sig Package {}
run example {}
@asimihsan
asimihsan / office_365_notifications.js
Created May 14, 2013 09:59
A Greasemonkey script to show notifications when there is any new mail in an Office 365 Outlook Web App tab.
// ==UserScript==
// @name Office 365 notifications
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description Show a Google Chrome notification when there is any unread mail.
// @match https://*/owa/*
// @copyright 2012+, You
// ==/UserScript==
var current_unread_count = 0;
@asimihsan
asimihsan / sidbar-rust.docs.js
Last active September 30, 2020 16:57
Greasemonkey script for forcefully enabling sidebar for Rust docs, even for narrow pages
// ==UserScript==
// @name Enable Sidebar for Rust docs
// @namespace https://asim.ihsan.io
// @version 0.1
// @description Always enable sidebar on Rust documentation pages.
// @author Asim Ihsan.
// @match https://doc.rust-lang.org/*
// @grant none
// @run-at document-idle
// ==/UserScript==
@asimihsan
asimihsan / !resuilts.md
Created February 28, 2014 17:29
HTML5 canvas drawing tabular data for massive (50k+) coloured, interactive, tables.

With click handlers

  • 5k rows takes <1s.330MB!
  • 10k rows takes <2s, 700MB!!