Skip to content

Instantly share code, notes, and snippets.

Avatar

Dimitris-Ilias Gkanatsios dgkanatsios

View GitHub Profile
@dgkanatsios
dgkanatsios / TapAction
Created Jul 25, 2014
A XAML Behavior for a small tap animation for Windows Phone, allows for an event to run after the Storyboard is completed
View TapAction
public class TapAction : Behavior<FrameworkElement>
{
public string EventAfterStoryboard
{
get { return (string)GetValue(EventAfterStoryboardProperty); }
set { SetValue(EventAfterStoryboardProperty, value); }
}
@dgkanatsios
dgkanatsios / BinaryListCheck.cs
Last active Jan 6, 2016
Code to insert/check existence of an item using binary operations
View BinaryListCheck.cs
static void Main(string[] args)
{
int storage = 19; //10011
int a = 1; //1
int b = 2; //10
int c = 4; //100
int d = 8;//1000
int e = 16;//10000
Console.WriteLine("--------------------------------");
Console.WriteLine("Check for the value 19 - 10011");
@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();
}
@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 / 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 / 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 / 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 / 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 / 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;
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}]};
You can’t perform that action at this time.