import random
import string
# The pool of characters to pick the characters for your password from
password_char_set = string.ascii_letters + string.digits + string.punctuation
def random_character():
return password_char_set[random.randint(0, len(password_char_set))]
This file contains 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
""" | |
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 |
This file contains 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
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" |
This file contains 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
There are situations where squashing commits is not favourable and is an anti-pattern. | |
Squashing is necessary when a series of commits represents an atomic unit of work, where an atomic unit of work is any work which if broken into two or more independent commits would render either or both of them functionally incomplete. as an extreme example, changing a single global variable name across two commits would likely break the first commit and so the two commits should be squashed. They should also be squashed because the two commits are thematically one (although thematic unity can be relative), but I view this as a less important reason. At any point, one should be able to go back to a given commit on master and ensure all tests pass. | |
Squashing should be avoided in situations where each commit in a given series is atomic, even if the commits deliver a feature in combination (unless, as alluded to above, some commits break the codebase in isolation). Incremental commits often represent the logical sequence o |
This file contains 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
""" | |
Script implements: | |
tail FILE_NAME NUMBER_OF_LINES_TO_TAIL | |
""" | |
import sys | |
def seek_eof(file): | |
file.seek(0, 2) |
This file contains 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
/* | |
* File invokes s3#listObjects recursively to retrieve all objects | |
*/ | |
const AWS = require('aws-sdk') | |
const s3 = new AWS.S3(); | |
let args = { | |
'Bucket': ADD_BUCKET_NAME_HERE, | |
'Prefix': ADD_PATH_PREFIX_HERE_OR_REMOVE_THIS_ATTRIBUTE | |
}; |
This file contains 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
#include <string.h> | |
#include <stdio.h> | |
/* | |
* Macro function that initializes a struct object | |
* and returns it. | |
* | |
* For this to work, a `{type}Init` function must | |
* be defined. | |
*/ |
This file contains 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 traceback | |
def print_stack_trace(): | |
try: | |
raise Exception | |
except Exception: | |
with open('~/.my_important_stack_trace', 'w') as file: | |
file.write('{}'.format(repr(traceback.format_stack()))) |
This file contains 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
lambda_1 = -> { puts 'From lambda_1: Hello, World!' } | |
lambda_2 = -> { puts 'From lambda_2: Hello, World!' } | |
proc_1 = Proc.new { puts 'From proc_1: Hello, World!' } | |
proc_2 = Proc.new { puts 'From proc_2: Hello, World!' } | |
def proc_or_lambda_called( | |
proc_or_lamdba_1, | |
proc_or_lamdba_2 | |
) |
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
.
- (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
NewerOlder