Skip to content

Instantly share code, notes, and snippets.

View hjerpbakk's full-sized avatar
🎄
Advent of Code

Runar Ovesen Hjerpbakk hjerpbakk

🎄
Advent of Code
View GitHub Profile
@hjerpbakk
hjerpbakk / ScaleToFit.cs
Created January 5, 2022 21:09
Scale an image to fit using C#, Xamarin and SpriteKit
var image = SKSpriteNode.FromTexture(SKTexture.FromImageNamed("image-name"));
image.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY());
var widthScaleFactor = device.DeviceSize.Width / image.Size.Width;
var heightScaleFactor = device.DeviceSize.Height / image.Size.Height;
var scaleFactor = widthScaleFactor < heightScaleFactor ? widthScaleFactor : heightScaleFactor;
image.SetScale(scaleFactor);
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Made by Illedan for Hjerpbakk.
**/
class Player

Keybase proof

I hereby claim:

  • I am sankra on github.
  • I am hjerpbakk (https://keybase.io/hjerpbakk) on keybase.
  • I have a public key ASD0WPn4xqzKx0rNe_nh90p3-vmL3m-D92BxYmuP0peB2go

To claim this, I am signing this object:

<Label Text="{Binding Decimals}" TextColor="#929292" />
@hjerpbakk
hjerpbakk / SettingsPage.xaml
Created January 15, 2016 10:39
The guilty cell
<Label Text="{Binding Decimals}" TextColor="{x:Static l:App.ValueColorString}" />
@hjerpbakk
hjerpbakk / XamlCompile.cs
Last active January 15, 2016 10:42
Example of enabling XAML compilation for an entire assembly in Xamarin.Forms
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace GoldenRatioCalculator {
public class App : Application {
public const string ValueColorString = "#929292";
public static readonly Color ValueColor = new Color(146D, 146D, 146D);
...
@hjerpbakk
hjerpbakk / struct.cs
Last active September 24, 2015 20:45
Example of a C# struct
public struct WidgetInformation : IEquatable<WidgetInformation>
{
private readonly Guid id;
private readonly string name;
public WidgetInformation(Guid id, string name)
{
this.id = id;
this.name = name;
}
@hjerpbakk
hjerpbakk / SKSpriteNodeExtensions.cs
Last active August 29, 2015 14:15
Extension method on SKSpriteNode which tiles a texture and applies it to the sprite.
/// <summary>
/// Creates a tiled texture and applies it to the <see cref="SKSpriteNode"/>.
/// </summary>
/// <param name="spriteNode">The <see cref="SKSpriteNode"/> to which the texture is applied.</param>
/// <param name="texture">The texture used as tiles.</param>
/// <param name="coverageSize">The size of the finished tiled texture.</param>
public static void TileSprite(this SKSpriteNode spriteNode, UIImage texture, CGSize coverageSize) {
var textureSize = new CGRect(CGPoint.Empty, texture.Size);
UIGraphics.BeginImageContext(coverageSize);
@hjerpbakk
hjerpbakk / ColorUtils.cs
Created February 15, 2015 18:37
Get the color given a ratio between a start and end color. From: http://www.hjerpbakk.com/blog/2015/2/15/gradient-colors-on-ios
public static UIColor ColorForRatio(float[] startColor, float[] endColor, float colorRatio) {
return UIColor.FromRGB(startColor[0] + (endColor[0] - startColor[0]) * colorRatio,
startColor[1] + (endColor[1] - startColor[1]) * colorRatio,
startColor[2] + (endColor[2] - startColor[2]) * colorRatio);
}
@hjerpbakk
hjerpbakk / CustomerFeeling.cs
Last active August 29, 2015 14:10
Showing usage of ShowRatingDialogAsync
var customerFeeling = await CustomerFeelingSheet.ShowRatingDialogAsync(parentVC);
switch(customerFeeling) {
case CustomerFeeling.LikeIt:
// "I like it!" was chosen
break;
case CustomerFeeling.CouldBeBetter:
// "It could be better..." was chosen
break;
default:
// "Cancel" was chosen