Skip to content

Instantly share code, notes, and snippets.

@Flayed
Flayed / ConfigurationService.cs
Last active May 2, 2018 16:25
Reflection Registration
public class ConfigurationService : IConfigurationService
{
public ConfigurationService(IDataService dataService)
{
_configurationSet = dataService.GetConfigurationSet();
}
public ITriangleConfiguration TriangleConfiguration => _configurationSet.TriangleConfiguration;
public ISquareConfiguration SquareConfiguration => _configurationSet.SquareConfiguration;
public ICircleConfiguration CircleConfiguration => _configurationSet.CircleConfiguration;
@Flayed
Flayed / EnumController.cs
Created May 1, 2018 19:24
Exposing Enums on Web API
public enum Day
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}
@Flayed
Flayed / EnumController.cs
Last active May 1, 2018 19:19
Enum to Tuple
private IEnumerable<(string key, int value)> GetEnum(Type enumType)
{
return Enum.GetValues(enumType)
.Cast<int>()
.Select(e => (Enum.GetName(enumType, e), e));
}
@Flayed
Flayed / main.cs
Created May 1, 2018 13:25
Number padding
int myNumber = 42;
// Adjust the first parameter to PadLeft to adjust the number of zeroes
string serialNumber = $"AXT{myNumber.ToString().PadLeft(5, '0')}";
// serialNumber = AXT00042
@Flayed
Flayed / main.cs
Created May 1, 2018 13:19
String Interpolation with Composite Formatting
int myNumber = 42;
// Adjust the number after D to adjust the number of leading zeroes
string serial = $"AXT{myNumber:D5}";
// serial = AXT00042
@Flayed
Flayed / asyncAwaitDemo.ts
Created April 18, 2018 15:26
TypeScript async/await
// A long running thing
doTheThing(a: number, b: number): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
// Long running call (just pretend, ok?)
const c = a + b;
if (c > 0) {
resolve(true);
}
else {
resolve(false);
@Flayed
Flayed / promiseDemo.ts
Created April 18, 2018 15:22
TypeScript promise
// A long running thing
doTheThing(a: number, b: number): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
// Long running call (just pretend, ok?)
const c = a + b;
if (c > 0) {
resolve(true);
}
else {
resolve(false);
@Flayed
Flayed / my-test.component.spec.ts
Created April 18, 2018 12:55
testing modal dialogs with jasmine
// Create the test module
@NgModule({
imports: [NgbModule.forRoot(), CommonModule],
exports: [YesNoModalComponent, MyCustomComponent],
declarations: [YesNoModalComponent, MyCustomComponent],
entryComponents: [YesNoModalComponent]
})
class DialogTestModule { }
describe('MyTestComponent', () => {
@Flayed
Flayed / DayOfWeek.cs
Created April 12, 2018 19:59
Packing Bytes
public enum DayOfWeek
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}
@Flayed
Flayed / my.component.html
Created March 29, 2018 16:33
ngModelChange
<select [(ngModel)]="myValue" (ngModelChange)="toNumber()">
<option *ngFor="let s of stuff" [value]="s.value">{{s.key}}</option>
</select>