Skip to content

Instantly share code, notes, and snippets.

View rahulrajaram's full-sized avatar

rahulrajaram rahulrajaram

View GitHub Profile
@rahulrajaram
rahulrajaram / .zsh
Created October 19, 2020 00:51
Git Aliases
alias gbr="git branch"
alias gap="git add -p"
alias gca="git commit --amend"
alias gco="git checkout"
alias gcp="git cherry-pick"
alias gcom="git checkout master"
alias gdc="git diff --cached"
alias gmv="git mv"
alias gpo="git pull origin"
alias gpl="git pull"
@rahulrajaram
rahulrajaram / .py
Created January 21, 2022 19:14
Printing distribution of floats over 1 second intervals
"""
This scripts loads a file that contains stringified floats expected
to be seconds since epoch listed in a comma-separated fashion as
follows:
"1638201720.793","1638201720.778","1638201720.770","1638201719.866","1638201710.152","1638201710.140","1638201709.727","1638201707.715","1638201704.069","1638201702.769","1638201702.757","1638201699.529","1638201699.363","1638201699.362","1638201689.308","1638201688.406","1638201686.458","1638201686.097","1638201685.893","1638201685.620","1638201685.350","1638201685.035","1638201684.650","1638201682.229","1638201679.695","1638201678.098","1638201677.825","1638201676.972","1638201676.640","1638201675.442","1638201674.020","1638201672.890","1638201672.862","1638201669.458","1638201669.364","1638201665.908","1638201665.606","1638201665.271","1638201665.138","1638201664.315","1638201664.298","1638201663.204","1638201662.234","1638201661.479","1638201661.368","1638201660.295","1638201660.256","1638201660.108","1638201660.097","1638201660.010","1638201659.797","163820165
@rahulrajaram
rahulrajaram / .md
Last active April 2, 2023 15:47
Python: Write to a file from multiple threads

I recently came across the need to spawn multiple threads, each of which needs to write to the same file. Since the file will experience contention from multiple resources, we need to guarantee thread-safety.

NOTE: The following examples work with Python 3.x. To execute the following programs using Python 2.7, please replace threading.get_ident() with thread.get_ident(). As a result, you would need to import thread and not threading.

  1. (The following example will take a very long time). It will create 200 threads, each of which will wait until a global lock is available for acquisition.
# threading_lock.py
import threading