Skip to content

Instantly share code, notes, and snippets.

View Odonno's full-sized avatar
🏠
Working from home

David Bottiau Odonno

🏠
Working from home
View GitHub Profile
@Odonno
Odonno / dragAndDropScrollingWP.cs
Created September 10, 2017 13:37
Drag'n'drop part of the NotificationCenter-like scrolling animation for WIndows Phone
private double _mouseVerticalPosition;
public MainPage()
{
InitializeComponent();
// take care of add events only one time
PointerEntered += MainPage_PointerEntered;
animationButton.PointerMoved += UIElement_OnPointerMoved;
}
@Odonno
Odonno / dispatcherScrollingWP.cs
Created September 10, 2017 13:38
Dispatcher call part of the NotificationCenter-like scrolling animation for WIndows Phone
private async void UIElement_OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
double pointerY = args.EventArgs.GetCurrentPoint(this).Position.Y;
double deltaY = pointerY - _mouseVerticalPosition;
double newHeigthValue = -animatedPanel.Margin.Bottom - deltaY;
// you need to stop the animation (from top to bottom) before the last block
if (newHeigthValue < 0)
newHeigthValue = 0;
@Odonno
Odonno / timerScrollingWP.cs
Created September 10, 2017 13:39
Timer part of the NotificationCenter-like scrolling animation for WIndows Phone
private DateTime _lastCalculation;
private async void UIElement_OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
// repeat UI refresh only every 15 milliseconds
if (DateTime.Now.Subtract(_lastCalculation).TotalMilliseconds > 15)
{
// your logic (animation with dispatcher part)
// refresh timer
@Odonno
Odonno / RxScrollingWP.cs
Created September 10, 2017 13:40
Reactive Extensions part of the NotificationCenter-like scrolling animation for WIndows Phone
public MainPage()
{
InitializeComponent();
PointerEntered += MainPage_PointerEntered;
// Create an Observable about PointerMove firing event each 15 miliseconds
var pointerMoved = Observable.FromEventPattern<PointerRoutedEventArgs>(animationButton, "PointerMoved")
.Sample(TimeSpan.FromMilliseconds(15))
.ObserveOnDispatcher(CoreDispatcherPriority.High);
@Odonno
Odonno / getPullRequestQuery.js
Created January 8, 2018 20:14
Example of a method returning a GraphQL query to get PRs of a repository
const getPullRequestQuery = (repoOwner: string, repoName: string, number: number): string => {
return `
query {
repository(owner: "${repoOwner}", name: "${repoName}") {
pullRequest(number: ${number}) {
id,
body,
comments(first: 100) {
edges {
node {
@Odonno
Odonno / OpenParkingCommand.cs
Last active July 6, 2019 19:43
OpenParkingCommand
public class OpenParkingCommand
{
public string ParkingName { get; set; }
}
@Odonno
Odonno / HandleOpenParkingCommand.cs
Created July 6, 2019 19:44
HandleOpenParkingCommand
public void Handle(OpenParkingCommand command)
{
var parking = _dbContext.Set<Models.Parking>()
.FirstOrDefault(p => p.Name == command.ParkingName);
if (parking == null)
{
throw new Exception($"Cannot find parking '{command.ParkingName}'.");
}
if (parking.IsOpened)
@Odonno
Odonno / GetParkingInfoQuery.cs
Created July 6, 2019 19:46
GetParkingInfoQuery
public class GetParkingInfoQuery
{
public string ParkingName { get; set; }
}
@Odonno
Odonno / HandleGetParkingInfoQuery.cs
Created July 6, 2019 19:47
HandleGetParkingInfoQuery
public ParkingInfo Handle(GetParkingInfoQuery query)
{
var parking = _dbContext.Set<Models.Parking>()
.Include(p => p.Places)
.FirstOrDefault(p => p.Name == query.ParkingName);
if (parking == null)
{
throw new Exception($"Cannot find parking '{query.ParkingName}'.");
}
@Odonno
Odonno / CommandStore.cs
Created July 6, 2019 19:50
CommandStore
public void Push(object command)
{
_dbContext.Set<Command>().Add(
new Command
{
Type = command.GetType().Name,
Data = JsonConvert.SerializeObject(command),
CreatedAt = DateTime.Now,
UserId = _authenticationService.GetUserId()
}