Skip to content

Instantly share code, notes, and snippets.

View dylanbeattie's full-sized avatar

Dylan Beattie dylanbeattie

View GitHub Profile
@dylanbeattie
dylanbeattie / while_e_coyote.cs
Created July 1, 2022 13:20
while() {} vs do {} while() loops using Roadrunner and Wile E. Coyote
abstract class Animal {
public int distanceFromEdge = 1;
protected bool edge => distanceFromEdge <= 0;
protected void run() {
distanceFromEdge--;
}
public abstract void go();
}
@dylanbeattie
dylanbeattie / ObjectToDynamic.cs
Last active November 6, 2021 11:20
An extension method on Object in C#, that converts statically-typed objects to dynamic objects with the same structure.
public static class ObjectExtensions {
public static dynamic ToDynamic(this object value) {
IDictionary<string, object> expando = new ExpandoObject();
var properties = TypeDescriptor.GetProperties(value.GetType());
foreach (PropertyDescriptor property in properties) {
expando.Add(property.Name, property.GetValue(value));
}
return (ExpandoObject)expando;
}
}
@dylanbeattie
dylanbeattie / whisper.rock
Created March 2, 2021 21:52
Rockstar: Whisper the Future
Forever takes a lifetime.
The sunset is silence (it seems)
Until a lifetime is nothing,
Roll a lifetime into your dreams,
Cast your dreams into the night,
Let the sunset be with the night.
Give back the sunset
Give back the night
@dylanbeattie
dylanbeattie / ObjectExtensions.cs
Created January 14, 2021 01:41
ObjectExtensions.ToDynamic
public static class ObjectExtensions {
public static dynamic ToDynamic(this object value) {
IDictionary<string, object> expando = new ExpandoObject();
var properties = TypeDescriptor.GetProperties(value.GetType());
foreach (PropertyDescriptor property in properties) {
expando.Add(property.Name, property.GetValue(value));
}
return (ExpandoObject)expando;
}
}
DECLARE @places TABLE (name nvarchar(max));
insert into @places(name) values('Aarhus');
insert into @places(name) values('Berlin');
insert into @places(name) values('Zurich');
insert into @places(name) values('Aachen');
select name from @places order by name COLLATE Latin1_General_CI_AI
select name from @places order by name COLLATE Danish_Norwegian_CI_AI
select name from @places order by name COLLATE Finnish_Swedish_CI_AI
using System;
using System.Text;
namespace DotNetSummitBy {
class Program {
static NormalizationForm[] forms = new[] {
NormalizationForm.FormC, NormalizationForm.FormD,
NormalizationForm.FormKC, NormalizationForm.FormKD
BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest;;Mr.
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;WORK;VOICE:(111) 555-1212
TEL;HOME;VOICE:(404) 555-1212
ADR;WORK;PREF:;;100 Waters Edge;Baytown;LA;30314;United States of America
@dylanbeattie
dylanbeattie / pivotal_markdown.js
Last active March 22, 2019 18:53
Javascript bookmarklet that will copy the selected stories in Pivotal Tracker to your clipboard as bullet points with Markdown hyperlinks
/*
This bookmarklet will let you select multiple stories in Pivotal Tracker and then
copy story details to your clipboard in Markdown format, as:
* Story name [#123456579](https://www.pivotaltracker.com/story/show/123456789)
* Story name [#123456579](https://www.pivotaltracker.com/story/show/123456789)
You can then paste this into your GitHub pull request description, then paste the resulting
rendered HTML into release emails, Slack, etc.
SET TLD=%COMPUTERNAME%
(
echo [req]
echo default_bits = 2048
echo prompt = no
echo default_md = sha256
echo x509_extensions = v3_req
echo distinguished_name = dn
echo:
#parse parameters supplied by TeamCity script step
param (
[string]$branch = "refs/heads/master",
[string]$branch_is_default = "true",
[string]$build_number = "0"
)
function Update-AssemblyVersion {
param ([string]$version)