Skip to content

Instantly share code, notes, and snippets.

View MiloszKrajewski's full-sized avatar

Milosz Krajewski MiloszKrajewski

  • Cambridge, UK
View GitHub Profile
@MiloszKrajewski
MiloszKrajewski / GetDrives.cs
Created March 29, 2016 08:29
Get drive information (C#, Windows, WMI)
var driveQuery = new ManagementObjectSearcher("select * from Win32_DiskDrive");
foreach (ManagementObject d in driveQuery.Get())
{
var deviceId = d.Properties["DeviceId"].Value;
//Console.WriteLine("Device");
//Console.WriteLine(d);
var partitionQueryText = string.Format("associators of {{{0}}} where AssocClass = Win32_DiskDriveToDiskPartition", d.Path.RelativePath);
var partitionQuery = new ManagementObjectSearcher(partitionQueryText);
foreach (ManagementObject p in partitionQuery.Get())
{
@MiloszKrajewski
MiloszKrajewski / StateMachine.fs
Created June 26, 2016 23:19
State Machine Construction Kit in F#
module StateMachine =
type State<'Event> =
| Next of ('Event -> State<'Event>)
| Stop
let feed state event =
match state with
| Stop -> failwith "Terminal state reached"
| Next handler -> event |> handler
param([String]$url, [String]$path="")
# It is a poor man's cURL, but can be used to download cURL
# powershell -file download.ps1 -url https://dl.uxnr.de/build/curl/curl_winssl_cross_x64/curl-7.50.3/curl-7.50.3.zip
# powershell -file download.ps1 -url https://cdn.rawgit.com/martinrotter/7za/master/7za.exe
# NOTE: may require "Set-ExecutionPolicy RemoteSigned"
if ($path -eq "") {
$path = [System.IO.Path]::GetFileName($url)
}
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace K4os.Fx;
internal static class ReflectionExtensions
{
// 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 NLog;
using NLog.Config;
using NLog.Targets;
using System.IO;
namespace ProductName
{
class Program
{
static void Main(string[] args)
## 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 System.Linq;
// ReSharper disable once CheckNamespace
namespace System;
/// <summary>
/// Adhoc disposable from action.
/// </summary>
public class Disposable: IDisposable
{
@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%\
@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
)