Skip to content

Instantly share code, notes, and snippets.

View wmeints's full-sized avatar

Willem Meints wmeints

View GitHub Profile
@wmeints
wmeints / PixelBuffer.cs
Created November 28, 2012 17:30
Component to write random pixels into a WriteableBitmap on Windows 8
/// <summary>
/// Allows for drawing random pixels into a writeable bitmap
/// </summary>
public class PixelBuffer
{
private WriteableBitmap _source;
private byte[] _pixels;
/// <summary>
/// Initializes a new instance of <see cref="PixelBuffer"/>
@wmeints
wmeints / public_ip.sh
Created January 28, 2015 08:12
Grab first IP-address of your linux machine
export PUBLIC_IP=$(ip addr show eth0 | grep "inet" | awk 'NR == 1 { print $2 }' | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
@wmeints
wmeints / RequestHandler.scala
Last active August 29, 2015 14:17
Extensions to make handling request in Spray framework easier to do
package nl.fizzylogic.restservice
import akka.actor.{Actor, ActorRef, Props, ReceiveTimeout}
import org.json4s.DefaultFormats
import spray.httpx.Json4sSupport
import spray.http.{StatusCode, StatusCodes}
import spray.routing.{HttpService, RequestContext}
import scala.concurrent.duration._
import scala.reflect.ClassTag
@wmeints
wmeints / PostIndexer.cs
Created September 13, 2015 14:42
Sample code for indexing logic in ASP.NET 5
using System;
using System.Threading.Tasks;
using Weblog.Models;
using Nest;
using Polly;
namespace Weblog.Services
{
public class PostIndexer: IPostIndexer
{
@wmeints
wmeints / Clients.cs
Last active November 12, 2016 15:11
IdentityServer4 configuration
public class Clients
{
public static IEnumerable<Client> All => new[]
{
new Client()
{
AccessTokenType = AccessTokenType.Jwt,
ClientId = "9c328f06-01c7-4429-9870-7e55a73e2870",
RedirectUris = new List<string>
{
@wmeints
wmeints / ProxyProxyDance.ps1
Last active May 16, 2024 10:12
This script allows you to enable and disable your proxy settings quickly in case you work from two different locations like your home office and a workplace where they require you to use a proxy.
$internetSettings = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings";
# Determines the current state of the proxy
function Get-ProxyState() {
$settings = Get-ItemProperty -Path $internetSettings;
return $settings.ProxyEnable;
}
# Enables the proxy.
# IMPORTANT: Change the defaults to something that is useful to you!
@wmeints
wmeints / mappings.ts
Last active December 29, 2016 14:25
Converter functions for mapping object values
export type MappingRule = (data: any) => any;
export type MappingRules<T> = { [P in keyof T]?: MappingRule };
export type MapperFunction<T> = (input: T) => any;
// Maps property values based on rules that you supplied.
// Properties for which no rule was supplied are copied to the output.
// NOTICE: This mapper function does not support renaming properties.
export function mapObject<T>(input: T, rules: MappingRules<T>): any {
if(input === undefined || input === null) {
return input;
@wmeints
wmeints / api-client.ts
Last active April 3, 2017 15:52
Short demo of how you can wrap standard HTTP behavior by adding additional operations on the observables it produces.
import { ApiRequestOptions } from './api-request-options.service';
import { Http, Response, RequestOptions, ResponseContentType } from '@angular/http';
import 'rxjs/add/observable/zip';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Rx';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
@Injectable()
@wmeints
wmeints / ITemplateService.cs
Last active August 27, 2020 03:20
A template service based on the ASP.NET Core razor engine
/// <summary>
/// Renders email content based on razor templates
/// </summary>
public interface ITemplateService
{
/// <summary>
/// Renders a template given the provided view model
/// </summary>
/// <typeparam name="TViewModel"></typeparam>
/// <param name="filename">Filename of the template to render</param>
@wmeints
wmeints / setup-cluster.sh
Created October 7, 2017 11:47
Setup kubernetes cluster quickly
#!/bin/sh
SUBSCRIPTION=$1
ENVIRONMENT=$2
az group create --name kubernetes-$ENVIRONMENT --location westeurope
az acs create --orchestrator-type kubernetes \
--resource-group kubernetes-$ENVIRONMENT \
--name $ENVIRONMENT \
--generate-ssh-keys \