Skip to content

Instantly share code, notes, and snippets.

Avatar

Syed Rafay srafay

View GitHub Profile
@srafay
srafay / mongodb.txt
Created Jan 21, 2020
Mongo DB useful cmds
View mongodb.txt
Get all collection size:
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
var byteToMB = 1024*1024;
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size']/byteToMB + "(MB) (" + stats[c]['storageSize']/byteToMB + ") (MB)"); }
View git_alias.txt
Log commits on terminal:
git config --global alias.tree log --pretty="%C(Yellow)%h %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s" --date=short --graph --abbrev-commit
Log branch commits:
git config --global alias.branchtree log --pretty="%C(Yellow)%h %C(reset)%ad (%C(Green)%cr%C(reset))%x09 %C(Cyan)%an: %C(reset)%s" --date=short --graph --abbrev-commit --first-parent --no-merges
@srafay
srafay / function_profiler.py
Created Jan 9, 2020
Profiling two functions using timeit in Python
View function_profiler.py
import timeit
from datetime import datetime
if __name__ == '__main__':
def test_get():
x = {'x':'123'}
return x.get('x')
def test_dict():
y = {'y':'123'}
return y['y']
@srafay
srafay / mask_middle
Created Apr 1, 2019
Function for masking middle elements in a string
View mask_middle
def mask_middle(text):
text = str(text)
if len(text) > 2:
return text[0] + "*" * (len(text) - 2) + text[len(text) - 1]
return "*" * len(text)
@srafay
srafay / fix git password prompt - Windows
Created Feb 15, 2019
Disable annoying bitbucket or source tree password prompts on windows
View fix git password prompt - Windows
$ git config --global --replace-all credential.interactive false
$ git config --global --replace-all credential.modalPrompt false
$ git config --edit --system
# remove line
helper = manager
# To disable openssh password prompt, add these 2 lines
[core]
@srafay
srafay / generate-request-form-data.py
Created Jan 16, 2019
Python Request for form-data
View generate-request-form-data.py
# Generates request data payload to be sent as 'form-data'
REQUEST_FORM_DATA_BOUNDARY = "REQUEST_FORM_DATA_BOUNDARY"
FORM_DATA_STARTING_PAYLOAD = '--{0}\r\nContent-Disposition: form-data; name=\\"'.format(REQUEST_FORM_DATA_BOUNDARY)
FORM_DATA_MIDDLE_PAYLOAD = '\"\r\n\r\n'
FORM_DATA_ENDING_PAYLOAD = '--{0}--'.format(REQUEST_FORM_DATA_BOUNDARY)
REQUEST_CUSTOM_HEADER = {
'content-type': "multipart/form-data; boundary={}".format(REQUEST_FORM_DATA_BOUNDARY),
'Content-Type': "",
'cache-control': "no-cache"