Skip to content

Instantly share code, notes, and snippets.

Avatar

Dimitris-Ilias Gkanatsios dgkanatsios

View GitHub Profile
View CustomTextInputDialog.cs
public sealed class CustomTextInputDialog : IDialog<string>
{
private CustomTextInputDialog()
{ }
public string InputPrompt { get; private set; }
public string WrongInputPrompt { get; private set; }
public ICustomInputValidator Validator { get; private set; }
View BookParkingDialogChainPart1.cs
public class BookParkingDialogChain : IDialog<object>
{
private string selectedName, selectedEmail, selectedPhoneNumber;
private string selectedLicensePlate;
private ParkingAreaDetails selectedParkingLocationDetails;
private DateTime arrivalDateTime, departureDateTime;
private ParkingLotDetails selectedParkingLot;
ParkAroundBot.Data.ReserveTravelResponse result;
private bool finalConfirmation;
View UpdateHighScore.js
var api = {
"post": function (req, res, next) {
var sqlstring = 'UPDATE Highscore SET score=@score,playername=@playername WHERE id=@id';
var query= {sql:sqlstring,
parameters:[
{name:'score',value:req.body.score},
{name:'playername',value:req.body.playername},
{name:'id',value:req.body.id}]};
@dgkanatsios
dgkanatsios / indexOnArrayLINQ
Created Jul 25, 2014
Find index on array via LINQ
View indexOnArrayLINQ
myObjects.Select((v, i) => new {myObject = v, index = i}).First(predicate).index;
@dgkanatsios
dgkanatsios / GetRandomNumbersAroundCorrectOne
Created Jul 25, 2014
Get random numbers given a margin around a particular one
View GetRandomNumbersAroundCorrectOne
public static List<int> GetRandomNumbersAroundCorrectOne(int correctOne, int margin, int count)
{
List<int> results = new List<int>();
for (int i = 0; i < count; i++)
{
//get the prosimo
int prosimo = 1;// ((NextRandom(1, 3) % 2) == 0) ? 1 : -1;
int number;
if (prosimo == 1)
{
@dgkanatsios
dgkanatsios / PlaySoundXNA
Created Jul 25, 2014
Snippet to play sound in Windows Phone via XNA Libraries
View PlaySoundXNA
static SoundEffectInstance sei;
public async static Task PlaySound(string soundPath, bool delay = true)
{
Stream waveFileStream = TitleContainer.OpenStream(soundPath);
SoundEffect se = SoundEffect.FromStream(waveFileStream);
sei = se.CreateInstance();
FrameworkDispatcher.Update();
sei.Play();
if (delay)
await Task.Delay(se.Duration);
@dgkanatsios
dgkanatsios / CreateOpacityStoryboard
Created Jul 25, 2014
A snippet to create a 0 to 1 opacity Storyboard for Windows Phone
View CreateOpacityStoryboard
public static Storyboard CreateOpacityStoryboard(FrameworkElement element)
{
Storyboard sb = new Storyboard();
DoubleAnimation opacityAnimation = new DoubleAnimation();
opacityAnimation.From = 0;
opacityAnimation.To = 1;
opacityAnimation.Duration = TimeSpan.FromMilliseconds(300);
Storyboard.SetTarget(opacityAnimation, element);
@dgkanatsios
dgkanatsios / WPResolutionHelper
Created Jul 25, 2014
Resolution helpers for Windows Phone
View WPResolutionHelper
public static class ResolutionHelper
{
public static Uri GetScaledImageUri(String imageName)
{
int scaleFactor = (int)Application.Current.Host.Content.ScaleFactor;
switch (scaleFactor)
{
case 100: return new Uri(imageName + "_wvga.png", UriKind.RelativeOrAbsolute);
case 150: return new Uri(imageName + "_720p.png", UriKind.RelativeOrAbsolute);
case 160: return new Uri(imageName + "_wxga.png", UriKind.RelativeOrAbsolute);
@dgkanatsios
dgkanatsios / WPDeviceInfo
Created Jul 25, 2014
A snippet to obtain device info on Windows Phone
View WPDeviceInfo
public static string GetDeviceInfo()
{
string returnvalue = string.Empty;
try
{
returnvalue = string.Format("manufacturer {0}, name {1}, firmware {2}, hardware {3}",
DeviceStatus.DeviceManufacturer, DeviceStatus.DeviceName, DeviceStatus.DeviceFirmwareVersion, DeviceStatus.DeviceHardwareVersion);
}
catch
@dgkanatsios
dgkanatsios / StoryboardEmulatesThreadSleep
Created Jul 25, 2014
A snippet to emulate Thread.Sleep in Windows Phone apps via XAML Storyboards
View StoryboardEmulatesThreadSleep
public async static Task CreateSleepStoryboard(int ms)
{
Storyboard sb = new Storyboard();
sb.Duration = TimeSpan.FromMilliseconds(ms);
await sb.BeginAsync();
}
You can’t perform that action at this time.