Skip to content

Instantly share code, notes, and snippets.

View srafay's full-sized avatar
:octocat:

Syed Rafay srafay

:octocat:
View GitHub Profile
@srafay
srafay / AspNetNavigationManagerLayoutRenderer.cs
Created July 17, 2022 06:10
Trying to create Layout Renderer for accessing NavigationManager Uri (Blazor)
using System.Text;
using NLog.LayoutRenderers;
namespace NLog.Web.LayoutRenderers
{
/// <summary>
/// Inject NavigationManager class which provides an abstraction for querying and managing URI navigation (for ASP.NET Core 3.0, 3.1, 5.0, 6.0, 7.0)
/// </summary>
/// <para>Example usage of ${aspnet-navigation-manager}:</para>
/// <example>
@srafay
srafay / GetCellsTableAndColumnName.cs
Created June 10, 2022 03:07
Get SFGrid Ref from CellSelectedHandler Event (Syncfusion Blazor C#)
void CellSelectedHandler<T>(CellSelectEventArgs<T> args, SfGrid<T> grid)
{
if (args.IsCtrlPressed)
{
System.Reflection.FieldInfo grid = args.GetType().GetField("Parent", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public);
var col = grid.FieldType.GetProperty("Columns");
var wrapped = ObjectAccessor.Create(col);
var argsFM = ObjectAccessor.Create(args);
var gridFM = ObjectAccessor.Create(grid);
@srafay
srafay / mongodb.txt
Created January 21, 2020 08:36
Mongo DB useful cmds
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)"); }
@srafay
srafay / git_alias.txt
Created January 20, 2020 07:24
Alias for Git
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 January 9, 2020 05:47
Profiling two functions using timeit in Python
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 April 1, 2019 05:50
Function for masking middle elements in a string
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 February 15, 2019 13:46
Disable annoying bitbucket or source tree password prompts on 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 January 16, 2019 05:18
Python Request for form-data
# 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"