Skip to content

Instantly share code, notes, and snippets.

View gethari's full-sized avatar

Hari Haran gethari

View GitHub Profile
@gethari
gethari / $PROFILE.ps1
Created February 8, 2024 05:01
Random oh-my-posh theme on every new terminal
function Get-RandomPoshThemeFile {
# Get the Posh-Themes directory path from the environment variable.
$poshThemesPath = $env:POSH_THEMES_PATH
# Check if the Posh-Themes directory exists.
if (!$poshThemesPath -or !(Test-Path $poshThemesPath)) {
throw "The POSH_THEMES_PATH environment variable is not set or the directory does not exist."
}
# Get a list of all theme files with the .omp.json extension.
echo This will first install chocolatey, then other tools
echo .
echo Browse https://chocolatey.org/packages for packages
echo .
echo Ensure that your cmd.exe runs as Administrator
echo .
powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco feature enable -n=allowGlobalConfirmation
static void Main(string[] args)
{
BenchmarkRunner.Run<Benchmark>();
}
[MemoryDiagnoser]
public class Benchmark {
private readonly SearchProperties _searchProperties;
public Benchmark() {
_properties = new Properties();
} [Benchmark(Baseline = true)]
public void WithDapper() {
var ids = new List < string > {
"05edc08b-c27f-4e4d-bb5c-0045959d93a4",
"a0290013-d568-407c-a1f3-340cdff10cb5", "4f6e2712-9412-4d84-90e4-44ccab389a44", "6f9eda0e-03ba-4456-8926-65713d9a35f9", "ec186495-8191-4e20-b090-72c2005f3681", "adc6f649-3058-4cc1-94c1-e9a36d9bda3d", "8406561b-247c-4e2e-a45a-ebe35b2af715"
public List<StageProperty> WithDapper(Guid id)
{
List<Property> result;
using (var connection = new SqlConnection(ConnectionString))
{
result = connection.QueryAsync<Property>(queryString, new
{
Id = id
}).Result.ToList();
}
public async Task<List<KeyValuePair<string, string>>> WithoutDapper(Guid id)
{
using (var connection = new SqlConnection(ConnectionString))
{
List<KeyValuePair<string, string>> propertiesList = new List<KeyValuePair<string, string>>();
SqlCommand command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("Id", id);
connection.Open();
SqlDataReader reader = await command.ExecuteReaderAsync();
public class MyClass
{
private readonly IMapper _mapper;
private readonly ILog _logger;
public MyClass(IMapper mapper,ILog logger){
_mapper = mapper;
_logger = logger;
}
public void DoSomething(){
_mapper.Map(appSetting, applicationSetting);
public class MyClass
{
private readonly IMapper _mapper;
public MyClass(IMapper mapper){
_mapper = mapper;
}
public void DoSomething(){
_mapper.Map(appSetting, applicationSetting);
}
}
public class AutoMapperModule: Module {
protected override void Load(ContainerBuilder builder) {
builder.RegisterAssemblyTypes(typeof(AutoMapperModule).Assembly).As < Profile > ();
builder.Register(context => new MapperConfiguration(cfg => {
foreach(var profile in context.Resolve < IEnumerable < Profile >> ()) {
cfg.AddProfile(profile);
}
})).AsSelf().SingleInstance();
public class PoOrder
{
public int ponumber { get; set; }
public string name { get; set; }
public string sku { get; set; }
public double price { get; set; }
public int quantity { get; set; }
public string messagetype { get; set; }
public ShipTo shipTo { get; set; }
public BillTo billTo { get; set; }