Skip to content

Instantly share code, notes, and snippets.

View vbfox's full-sized avatar
❄️
Winter is coming

Julien Roncaglia vbfox

❄️
Winter is coming
View GitHub Profile
namespace HackNSlash
{
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
@vbfox
vbfox / TwitterRandomSquareBackground.cs
Created April 8, 2014 21:56
Generate a bitmap composed of random squares in different shades of blue
void Main()
{
var bmp = new Bitmap(1920, 1200);
const int size = 20;
Random r = new Random();
Color colorA = Color.FromArgb(0, 148, 255);
Color colorB = Color.FromArgb(145, 216, 255);
@vbfox
vbfox / ReferenceMethodGroup.cs
Last active August 29, 2015 13:59
DOES NOT WORK, GENERATED IL DOES NOT CONTAIN THE EXPECTED CALL. An exploration on how a mock framework can get a call to a method without specifying the arguments and then mock the real call. The C# compiler make it hard as method groups can't appear anywhere in the language. Well except in one place it seem...
void Main()
{
IFoo foo = new Foo();
A.CallMethodWithAnyArgs(() => A.Hack(__arglist(foo.Bar)));
}
public static class A
{
public static void CallMethodWithAnyArgs(Action callSpecification)
{
@vbfox
vbfox / teamCityEscape.fsx
Created August 21, 2014 08:05
FAKE: Escape special team city comments
let private teamCityEscapeChars =
[ ('\'', "|'"); ('\r', "|r"); ('\n', "|n"); ('|', "||"); ('[', "|["); (']', "|]") ]
|> Map.ofSeq
let private teamCityEscape s =
let final = s |> Seq.map (fun c ->
match teamCityEscapeChars |> Map.tryFind c with
| Some(replacement) -> replacement
| _ -> string(c)
@vbfox
vbfox / Zip7.fsx
Created August 21, 2014 08:07
Call 7-Zip from a FAKE F# script
let private encodeParameterArgument original =
if String.IsNullOrEmpty(original) then
original
else
let temp = Regex.Replace(original, @"(\\*)" + "\"", @"$1\$0");
Regex.Replace(temp, @"^(.*\s.*?)(\\*)$", "\"$1$2$2\"");
let private encodeParameterArguments (arguments:seq<string>) =
String.Join(" ", arguments |> Seq.map encodeParameterArgument)
@vbfox
vbfox / HtmlFragment.cs
Created August 27, 2014 13:46
HTML Fragment for clipboard
static class HtmlFragment
{
const string HTML_FRAGMENT_HEADER = "Version:0.9\r\nStartHTML:{0:000000}\r\nEndHTML:{1:000000}"
+ "\r\nStartFragment:{2:000000}\r\nEndFragment:{3:000000}\r\n";
const string HTML_FRAGMENT_BEGIN = "<html>\r\n<head>\r\n"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={0}\">\r\n</head>\r\n"
+ "<body>\r\n<!--StartFragment-->";
const string HTML_FRAGMENT_END = "<!--EndFragment-->\r\n</body>\r\n</html>\r\n";
@vbfox
vbfox / keybase.md
Created September 25, 2014 09:22
keybase

Keybase proof

I hereby claim:

  • I am vbfox on github.
  • I am vbfox (https://keybase.io/vbfox) on keybase.
  • I have a public key whose fingerprint is 38F5 0CAE 98D0 1EC5 F05F 75F5 E837 FAF6 2D23 1094

To claim this, I am signing this object:

@vbfox
vbfox / fixacls.ps1
Created October 29, 2014 12:36
Fixes "This access control list is not in canonical form" on a folder
param([string]$dir);
$out = icacls "$dir" /verify /t /q
Foreach($line in $out)
{
if ($line -match '(.:[^:]*): (.*)')
{
$path = $Matches[1]
$acl = Get-Acl $path
Set-Acl $path $acl
@vbfox
vbfox / UpdateAllNuget.md
Created November 19, 2014 08:25
Update all Nuget packages in a solution matched by name

From my CoderWall: https://coderwall.com/p/gvrn4w

Here is a better version of the code already present on Coderwall and on the official bug tracker.

The complexity of the original one is too big as it tries to update all packages found for all projects, instead of just the packages present on each project.

This one is a lot quicker to update everything in a big solution :

ForEach($project in get-project -all) { ForEach($package in Get-Package -ProjectName $project.ProjectName | ?{ $_.Id -like 'MyCompany*'}) { Update-Package -ProjectName $project.ProjectName -Id $package.Id;} }
@vbfox
vbfox / nullarg.DotSettings
Created November 26, 2014 17:16
NullReferenceException check -> custom function with ReSharper Structural Search And replace
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=2F4A0295AA4DD848965FCA6DA262D8B4/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=2F4A0295AA4DD848965FCA6DA262D8B4/Comment/@EntryValue">ArgumentNullException Thrown</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=2F4A0295AA4DD848965FCA6DA262D8B4/IsReplacePattern/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=2F4A0295AA4DD848965FCA6DA262D8B4/LanguageName/@EntryValue">CSHARP</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/StructuralSearch/Pattern/=2F4A0295AA4DD848965FCA6DA262D8B4/ReplaceComment/@EntryV