Skip to content

Instantly share code, notes, and snippets.

@M-Zuber
M-Zuber / Withfunc.cs
Last active Dec 20, 2019
Use case for generic attributes in c#
View Withfunc.cs
using System;
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
sealed class LoggerAttribute<T> : Attribute
{
readonly Func<T, string> _template;
public LoggerAttribute(Func<T, string> positionalString)
{
_template = positionalString;
}
@M-Zuber
M-Zuber / cheer.snippet
Created Feb 17, 2019
VS Snippet to insert cheer messages during a live stream
View cheer.snippet
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>cheer</Title>
<Shortcut>cheer</Shortcut>
<Description>Code snippet for cheers during a live stream</Description>
<Author>Mordechai Zuber</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
View Program.cs
using System;
using System.Threading.Tasks;
namespace Example
{
internal class Program
{
private static void Main()
{
var t1 = (f: new Foo { A = 1 }, b: new Bar { B = 2 });
@M-Zuber
M-Zuber / generic.ts
Created Feb 21, 2018
Test case to understand how to use typescript generics properly. needs noImplicitAny set
View generic.ts
interface FilterOption {
key: string | number;
displayValue: string;
predicate: <TEntity>(e: TEntity) => boolean;
}
interface Registration {
id: number;
name: string;
date: string;
@M-Zuber
M-Zuber / info.md
Created Apr 20, 2017
typescript config/concepts explanations
View info.md
  • target tells TS what type of JS to generate, for es5 for conversion is required (for example let/const -> var, class -> function + prototype, etc.), whereas es6 can just leave the original code as is (after removing type information).
  • types tells TS about what types exists and what their API is. When using lib you are asking TS to add known core types that it already has definitions for, without having to add those yourself (for example, @types/core-js). When you import you adding more types that TS knows about. Additionally, you can use the types configuration property to add global types.
  • polyfills are required at runtime to ensure that older browsers can use the constructs (such as Promise) that exist natively in modern browsers. At this point, TS is not involved at all.
@M-Zuber
M-Zuber / foo.cs
Created Jan 30, 2017
Wierd IntelliSense thing
View foo.cs
public class Foo
{
public OtherClass GetThing(params object[] stuff) => new OtherClass(stuff);
public void DoThing()
{
var first = GetThing(..);
// This was reported as having type `dynamic`
var second = GetThing(..);
}
@M-Zuber
M-Zuber / Keybase.md
Created Aug 1, 2016
Keybase.io verification
View Keybase.md

Keybase proof

I hereby claim:

  • I am M-Zuber on github.
  • I am mordzuber (https://keybase.io/mordzuber) on keybase.
  • I have a public key whose fingerprint is 6288 6DCE 6286 2CFC 772B 0B9E F0AA 364E A4D6 F64B

To claim this, I am signing this object:

@M-Zuber
M-Zuber / fto.md
Last active Feb 5, 2016
first-timer issue for octokit.net
View fto.md