Skip to content

Instantly share code, notes, and snippets.

@ptsurbeleu
ptsurbeleu / HomeController.cs
Last active December 14, 2015 18:09 — forked from johnnyreilly/DemoAreaRegistration.cs
This is a forked version of John Reilly's gist that has been specifically tailored to bring testability for one of the Controller.Url.RouteUrl overloads. See below some code as an example of how this could done. P.S. Some features has been cut off from the original gist.
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace DemoApp.Controllers
{
public class HomeController : System.Web.Mvc.Controller
{
//....
public ActionResult About()
@ptsurbeleu
ptsurbeleu / example.cs
Created October 6, 2015 18:31
How to decode JWT token
// NOTE: For that code to work, you need install System.IdentityModel.Tokens.Jwt package from NuGet (the link includes the latest stable version)
// Link: https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/4.0.2.206221351
using System.IdentityModel.Tokens;
// a sample jwt encoded token string which is supposed to be extracted from 'Authorization' HTTP header in your Web Api controller
var tokenString = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8wMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJpYXQiOiIxNDI4MDM2NTM5IiwibmJmIjoiMTQyODAzNjUzOSIsImV4cCI6IjE0MjgwNDA0MzkiLCJ2ZXIiOiIxLjAiLCJ0aWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJhbXIiOiJwd2QiLCJvaWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJlbWFpbCI6Impkb2VAbGl2ZS5jb20iLCJwdWlkIjoiSm9obiBEb2UiLCJpZHAiOiJsaXZlLmNvbSIsImFsdHNlY2lkIjoiMTpsaXZlLmNvbTowMDAwMDAwMDAwMDAwMDAw
@ptsurbeleu
ptsurbeleu / ChangePassword.html
Last active October 21, 2015 01:21
Async validation in UI extension (Windows Azure Pack)
<!-- SYNOPSIS: Sample HTML snippet from an imaginary UI extension that makes use of async validation -->
<!-- NOTE: This UI snippet will send an ajax request to ChangePassword/ValidatePasswordStrength uri to validate the users' input -->
<div>
<div id="changeMyPasswordForm">
<div class="drawer-form-item">
<label for="newPassword">New Password</label>
<div>
<input id="newPassword" name="newPassword" type="text" data-val="true"
data-val-length-min="6" data-val-length-max="64"
data-val-remote="enabled"
@ptsurbeleu
ptsurbeleu / description.js
Created November 2, 2015 19:20
Adhoc debug description for a closure object in JavaScript
// Builds human-readable representation of the specified object for debugging purposes.
function debugDescription(object: any, category: string): string {
var tuples = [];
for (var property in object) {
if (object.hasOwnProperty(property)) {
if (typeof object[property] === "object") {
tuples.push("'" + property + "': " + debugDescription(object[property], ""));
} else {
tuples.push("'" + property + "': '" + object[property] + "'");
}
@ptsurbeleu
ptsurbeleu / gist:509e00d145a5057aa3e8
Created November 2, 2015 19:23
Git: Compute difference between DEV and FEATURE branches
git log --oneline dev ^^feature
@ptsurbeleu
ptsurbeleu / startingWith.go
Last active November 3, 2015 06:13
Getting started with Go
Wonderful guide, very concise and actionable - https://gobyexample.com/hello-world
An official tour of Go, good but not great - https://tour.golang.org
@ptsurbeleu
ptsurbeleu / rails_load_path_tips.md
Created January 19, 2017 01:16 — forked from maxim/rails_load_path_tips.md
How to use rails load paths, app, and lib directories.

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/

@ptsurbeleu
ptsurbeleu / sample.rb
Created May 17, 2017 20:37
An example of how to mock external service errors
class MyService
def send_request(number)
# calls an external service and might encounter an error
puts "... sending request ..."
end
def call_me_maybe(number)
begin
# first attempt
self.send_request(number)
@ptsurbeleu
ptsurbeleu / cloud-config.yml
Last active September 1, 2017 17:33
Hand-crafted cloud-config.yml to co-locate Kontena Master & The Only Initial Node on the same Packet server
#cloud-config
write_files:
- path: /etc/kontena-server.env
permissions: 0600
owner: root
content: |
KONTENA_VERSION=latest
KONTENA_VAULT_KEY=ghV5TK5yl4zsfJlW4sWuhdPMc1ngLFAOzDYJwTSnjQpK096VWwDcTD5BKrV0ZyNZ
KONTENA_VAULT_IV=usPWA6tbnzdt0sjZI0eYFVaqZgk4pgQqOlPxrpGkOJcv9yHTRhpMW5N3ugKp7wHe
KONTENA_INITIAL_ADMIN_CODE=CoreOS999
@ptsurbeleu
ptsurbeleu / warning_tag.rb
Last active January 16, 2018 02:56
Custom Liquid tag for Jekyll (warning)
# MIT License
# Copyright (c) 2018 Pavel Tsurbeleu and StaticPages Inc (staticpages.io)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions: