Skip to content

Instantly share code, notes, and snippets.

View MiloszKrajewski's full-sized avatar

Milosz Krajewski MiloszKrajewski

  • Cambridge, UK
View GitHub Profile
curl -L -o 7z.exe http://bit.ly/2o0eAeK
curl -L -o net20-empty.zip http://bit.ly/2y4rWM1
curl -L -o paket.cmd http://bit.ly/2yJ6lWg
curl -L -o fake.cmd http://bit.ly/2nu6TcJ
curl -L -o build.fsx http://bit.ly/2pksTem
curl -L -o protoc.cmd http://bit.ly/2n2h8cI
public static Func<string> Defer(this string message)
{
return () => message ?? "<null>";
}
public static Func<string> Defer(Exception exception)
{
return () => {
if (exception == null)
return "<null>";
@MiloszKrajewski
MiloszKrajewski / ExplainException.cs
Last active March 15, 2023 11:29
Explains exception (including all levels)
public static class ExceptionExtensions
{
public static T Rethrow<T>(this T exception)
where T: Exception
{
ExceptionDispatchInfo.Capture(exception).Throw();
// it never actually gets returned, but allows to do some syntactic trick sometimes
return exception;
}
@MiloszKrajewski
MiloszKrajewski / build.fsx
Last active April 2, 2017 21:22
F#ake batch file / bootstrapper
#r ".fake/FakeLib.dll"
open Fake
let build = MSBuild "" "Build" [ ("Configuration", "Release"); ("Platform", "Any CPU") ] >> ignore
Target "Clear" (fun _ ->
!! "**/bin/" ++ "**/obj/" |> DeleteDirs
)
@MiloszKrajewski
MiloszKrajewski / paket.cmd
Last active March 6, 2018 23:51
Paket batch file / bootstrapper
@echo off
setlocal
set target=%~dp0\.paket
set paket=%target%\paket.exe
if not exist %paket% (
rmdir /q /s %temp%\nuget\paket.bootstrapper 2> nul
nuget install -out %temp%\nuget -excludeversion paket.bootstrapper
xcopy %temp%\nuget\paket.bootstrapper\tools\* %target%\
using System.Linq;
// ReSharper disable once CheckNamespace
namespace System;
/// <summary>
/// Adhoc disposable from action.
/// </summary>
public class Disposable: IDisposable
{
## NOTE: pip install requests
import requests
import sys
import argparse
from shutil import copyfileobj
from urllib.parse import urlparse
from os.path import basename, isfile
using NLog;
using NLog.Config;
using NLog.Targets;
using System.IO;
namespace ProductName
{
class Program
{
static void Main(string[] args)
// NOTE: this method does not throw it just "prepares to be thrown"
static Exception Rethrow(this Exception ex)
{
try
{
typeof(Exception)
.GetMethod("PrepForRemoting", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(ex, new object[0]);
}
catch (Exception)
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace K4os.Fx;
internal static class ReflectionExtensions
{