Skip to content

Instantly share code, notes, and snippets.

View rasmuschristensen's full-sized avatar
💭
Working remotely

Rasmus Tolstrup Christensen rasmuschristensen

💭
Working remotely
View GitHub Profile
@rasmuschristensen
rasmuschristensen / javascript startswith
Created January 26, 2016 13:02
StartsWith in javascript based on pure javascript using substring or lastIndexOf
var data = 'Just something great';
var input = 'Jus';
// this one
data.substring(0, input.length) === input;
// or this one
data.lastIndexOf(input, 0) === 0
@rasmuschristensen
rasmuschristensen / KnockoutJS Dump
Created January 26, 2016 13:20
Debug KnockoutJS Dump binding
ko.bindingHandlers.dump = {
init: function (element, valueAccessor, allBindingsAccessor, viewmodel, bindingContext) {
var context = valueAccessor();
var allBindings = allBindingsAccessor();
var pre = document.createElement('pre');
element.appendChild(pre);
var dumpJSON = ko.computed({
read: function () {
@rasmuschristensen
rasmuschristensen / BootboxJSCustomWidth
Created March 4, 2016 10:10
Changing the width of bootbox dialog
// css
.dialogWide > .modal-dialog {
width: 80% !important;
}
// script
bootbox.dialog({
className: "dialogWide",
title: "Foo",
message: "what to say, go wide",
buttons: {
@rasmuschristensen
rasmuschristensen / CalculateEasterDay
Created March 22, 2016 09:47
Calculate easter day of a year. incl. leap year support
/// <summary>
/// Calculation based on https://da.wikipedia.org/wiki/P%C3%A5ske
/// </summary>
/// <param name="year"></param>
/// <returns></returns>
public DateTime GetEasterDateOfYear(int year)
{
int a = year % 19;
int b = (int)Math.Floor(year / 100m);//Heltal (rundet) ned) af aar / 100
int c = year % 100;
cropTextImage.SaveToPhotosAlbum((imageSave, error) =>
{
//you can retrieve the saved UI Image as well if needed using
if (error != null)
{
Debug.WriteLine(error.ToString());
}
});
public byte[] MakeGrayScale(byte[] imageAsBytes)
{
UIImage image = ImageFromByteArray(imageAsBytes);
var height = image.Size.Height;
var width = image.Size.Width;
var imageRect = new CGRect(0, 0, width, height);
using (CGBitmapContext context = new CGBitmapContext(IntPtr.Zero,
(int)width, (int)height, 8,
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow)
{
if (Xamarin.Forms.Application.Current == null || Xamarin.Forms.Application.Current.MainPage == null)
{
return UIInterfaceOrientationMask.Portrait;
}
var navigationPage = Xamarin.Forms.Application.Current.MainPage as NavigationPage;
@rasmuschristensen
rasmuschristensen / WrapPanel
Last active May 4, 2017 17:11
Xamarin Forms WrapPanel raw 1st edition, not complete yet.....
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using Xamarin.Forms;
namespace Controls.Bypassion.dk
{
public class WrapLayout : Layout<View>
{
private $TYPE$ _$name$;
public $TYPE$ $NAME$
{
get { return _$name$; }
set { SetProperty(ref _$name$, value); }
}
@rasmuschristensen
rasmuschristensen / AutoREST PS
Created December 9, 2016 22:29
A Powershell to autogenerate C# proxies from a swagger endpoint
$swaggerEndpoint = "http://localhost:9000/swagger/docs/v1"
$outputDirectory = "targetfolder"
$autoRestRelativePath = "..\..\packages\autorest.0.17.3\tools\AutoRest.exe"
& $autoRestRelativePath -Input $swaggerEndpoint -Namespace "com.myproject.Client.Proxies.targetfolder" -OutputDirectory $outputDirectory -CodeGenerator CSharp