Skip to content

Instantly share code, notes, and snippets.

View tmacharia's full-sized avatar
:octocat:
Focusing

Timothy Macharia tmacharia

:octocat:
Focusing
  • Nairobi, KE
View GitHub Profile
@tmacharia
tmacharia / aspnet-core-get-user-ipaddress.cs
Created September 4, 2019 18:40
Asp.Net Core Get Request IpAddress
public static string GetIpAddress(this HttpContext _context, bool tryUseXForwardHeader = true)
{
string ip = string.Empty;
/*-----------------------------------------------------------------------------------
| Todo support new "Forwarded" header (2014)
| https://en.wikipedia.org/wiki/X-Forwarded-For
|
| X-Forwarded-For (csv list): Using the First entry in the list seems to work
| for 99% of cases however it has been suggested that a better (although tedious)
@tmacharia
tmacharia / ZoneExts.cs
Last active November 16, 2019 01:22
For achieving a high level of accuracy in detecting the location a machine/user in .NET/C# without location/gps permissions, this helper class contains a bunch of methods & properties to achieve using the machine's LocalTimeZone and looking it up against a known list of timezone info schema that maps to a country's 2-Letter ISO Code.
namespace Common
{
using System.Linq;
public class ZoneInfo
{
/// <summary>
/// 2-Letter ISO code representing the country where the timezone is.
/// </summary>
public string Code { get; set; }
/// <summary>
@tmacharia
tmacharia / uwp-clock-one-frame.xaml
Last active November 24, 2019 20:01
Clock shape first
<Grid Background="#242631" Height="400" Width="400" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border x:Name="ClockEllipse" CornerRadius="400" Background="#323443"/>
</Grid>
@tmacharia
tmacharia / uwp-clock-one-markers.xaml
Last active November 24, 2019 20:14
Clock frame with 12,3,6,and 9 O'Clock plus the central Markers
<Grid Background="#242631" Height="400" Width="400" VerticalAlignment="Center" HorizontalAlignment="Center">
<!-- Clock Ellipse/Frame -->
<Border x:Name="ClockEllipse" CornerRadius="400" Background="#323443"/>
<!-- Central Markers -->
<Border Height="30" Width="30" CornerRadius="70" Background="#242631"/>
<Border Height="12" Width="12" CornerRadius="20" Background="LightGray"/>
<!-- O'Clock Markers -->
<Border Height="10" Width="10" CornerRadius="10" Margin="15" Background="DeepPink" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<Grid Background="#242631" Height="400" Width="400" VerticalAlignment="Center" HorizontalAlignment="Center">
<!-- Clock Ellipse/Frame -->
<Border x:Name="ClockEllipse" CornerRadius="400" Background="#323443"/>
<Canvas HorizontalAlignment="Center" VerticalAlignment="Center">
<Path x:Name="SecHandPath" StrokeThickness="1" Stroke="DeepPink" Data="M 0,40 L 0 -150" RenderTransformOrigin="0,0">
<Path.Resources>
<Storyboard x:Name="SpinSecHandStoryBoard">
<DoubleAnimation x:Name="SpinSecHandAnim" Storyboard.TargetName="SecHandPath" FillBehavior="HoldEnd" AutoReverse="False" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
</DoubleAnimation>
using System;
using Windows.Xaml;
namespace uwp.clock.backend
{
public sealed partial class UwpClockPage : Page
{
private readonly DispatcherTimer _timer;
private double PreviousAngle = 0;
public UwpClockPage()
@tmacharia
tmacharia / uwp-gradient-stops.cs
Last active February 1, 2020 00:15
Generate a smooth looking linear color gradient for use in UWP apps that for example scales from transparent to Black
private void Usage()
{
MyGrid.Background = new LinearGradientBrush()
{
GradientStops = GetGradientStops(Colors.Black, 8)
};
}
/// <summary>
/// Generate a smooth <see cref="GradientStopCollection"/> from transparent to the specified target
/// <see cref="Color"/> with the specified <paramref name="numOfStops"/>.

For publishing, open up a new terminal/command prompt and follow the following steps.

  1. Change the directory to the KTDASMS folder

For example, this is what i need to type to access that folder on my local machine, do the same on your machine changing the path shown below to reflect the location of the KTDASMS folder on your machine

cd "C:\Users\tmacharia\Downloads\Notifyr 2.0\Notifyr 2.0\KTDASMS"
@tmacharia
tmacharia / miniprofiler-sql-script.sql
Created December 2, 2021 23:53
MSSQL Script to create/initialize default tables for MiniProfiler
CREATE TABLE MiniProfilers
(
RowId integer not null identity constraint PK_MiniProfilers primary key clustered, -- Need a clustered primary key for SQL Azure
Id uniqueidentifier not null, -- don't cluster on a guid
RootTimingId uniqueidentifier null,
Name nvarchar(200) null,
Started datetime not null,
DurationMilliseconds decimal(15,1) not null,
[User] nvarchar(100) null,
HasUserViewed bit not null,