Skip to content

Instantly share code, notes, and snippets.

@M-Zuber
M-Zuber / Withfunc.cs
Last active December 20, 2019 05:36
Use case for generic attributes in c#
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 February 17, 2019 16:51
VS Snippet to insert cheer messages during a live stream
<?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>
@M-Zuber
M-Zuber / Program.cs
Created November 5, 2018 08:30
tuple equality
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 February 21, 2018 10:01
Test case to understand how to use typescript generics properly. needs noImplicitAny set
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 April 20, 2017 19:00
typescript config/concepts explanations
  • 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 January 30, 2017 20:07
Wierd IntelliSense thing
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 August 1, 2016 07:13
Keybase.io verification

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 February 5, 2016 05:29
first-timer issue for octokit.net