Skip to content

Instantly share code, notes, and snippets.

@amitsaha
amitsaha / tail.py
Last active April 30, 2024 11:49
Simple implementation of the tail command in Python
'''
Basic tail command implementation
Usage:
tail.py filename numlines
'''
import sys
import linecache
@amitsaha
amitsaha / virsh_cheat.rst
Created September 4, 2012 00:05
Virsh cheat sheet

Domain Management

  • List domains: #virsh list --all
  • Undefine domains: #virst undefine <domain-name>

Volume Management

  • List all volumes in pool 'default': #virsh vol-list default
@amitsaha
amitsaha / ls.rst
Last active December 29, 2023 19:00
How does `ls` work?

How does ls work?

I wanted to be really able to explain to a fair amount of detail how does the program ls actually work right from the moment you type the command name and hit ENTER. What goes on in user space and and in kernel space? This is my attempt and what I have learned so far on Linux (Fedora 19, 3.x kernel).

How does the shell find the location of 'ls' ?

@amitsaha
amitsaha / dynamodbtablescan.ps1
Created November 16, 2018 02:32
Powershell + DynamoDB table scan
function Get-DynamoByPrefix($table, $keyPrefix)
{
$region = "ap-southeast-2"
$regionEndpoint=[Amazon.RegionEndPoint]::GetBySystemName($region)
$client = New-Object Amazon.DynamoDBv2.AmazonDynamoDBClient($regionEndpoint)
$req = New-Object Amazon.DynamoDBv2.Model.ScanRequest
$req.TableName = $table
$result = $client.Scan($req)
$result.Items | Where-Object {$_.Key.S.StartsWith($keyPrefix)} | ForEach-Object {
@amitsaha
amitsaha / nginx.conf
Last active December 12, 2022 09:38
nginx conf + geoip2
# blog post: https://echorand.me/nginx-and-geoip2.html
worker_processes auto;
daemon off;
error_log /dev/stdout warn;
include /etc/nginx/modules/*.conf;
load_module modules/ngx_http_geoip2_module.so;
events {
}
@amitsaha
amitsaha / cloghandler.py
Created September 20, 2012 00:42
cloghandler source
# Copyright 2008 Lowell Alleman
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
@amitsaha
amitsaha / inspect_demo.py
Created August 27, 2012 09:04
Demo code using the Python inspect module
''' Demo script experimenting with various features of the
inspect module
'''
# To be run with Python3.3
from inspect_test import MyClass
from inspect_test import myfunc
from inspect_test import mygen
@amitsaha
amitsaha / picloud_rest.c
Last active August 15, 2022 06:35
PiCloud REST call from C using libcurl
/* Invokes a published function in PiCloud and then
retrieves the results.
Uses libcurl. Compile using the -lcurl flag.
See: http://echorand.me/2012/01/27/picloud-and-rest-api-with-c-client/
*/
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
@amitsaha
amitsaha / config_dict.py
Created July 7, 2012 07:00
Dumps a Config file into a Python dictionary
''' Dumps a config file of the type readable by ConfigParser
into a dictionary
Ref: http://docs.python.org/library/configparser.html
'''
import sys
import ConfigParser
class GetDict:
@amitsaha
amitsaha / notes.md
Last active May 28, 2022 07:45
Extras handling in micropip

Explanation of micropip's extras handling

From my understanding, a transaction corresponds to a single micropip.install() command.

The method add_requirement_inner() gets called for each package that we will be installing as part of the current microppip transaction.

So, consider the following:

  • pkga with optional dependency marker, all which will bring in packages, depa and depb