Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / Program.cs
Last active August 29, 2015 14:06
Decompiled TryParse boolean with declaration expression
bool flag;
if (bool.TryParse("true", out flag))
{
Console.WriteLine("This is a bool with value. " + flag);
}
else
{
Console.WriteLine("Not a bool, yo! " + flag);
}
@ThomasArdal
ThomasArdal / Program.cs
Created September 25, 2014 08:17
Static usings
using System.Console;
...
if (bool.TryParse("true", out var result))
{
WriteLine("This is a bool with value. " + result);
}
else
{
@ThomasArdal
ThomasArdal / SomeClass.cs
Last active August 29, 2015 14:06
Standard try catch
try
{
DoSomeHttpRequest();
}
catch (System.Web.HttpException e)
{
switch (e.GetHttpCode())
{
case 400:
WriteLine("Bad Request");
@ThomasArdal
ThomasArdal / SomeClass.cs
Last active August 29, 2015 14:06
Try catch with exception filters
try
{
DoSomeHttpRequest();
}
catch (System.Web.HttpException e) if (e.GetHttpCode() == 400)
{
WriteLine("Not Found");
}
catch (System.Web.HttpException e) if (e.GetHttpCode() == 500)
{
@ThomasArdal
ThomasArdal / SomeClass.cs
Last active August 29, 2015 14:06
Decompiled try catch with exception filter
try
{
Program.DoSomeHttpRequest();
return;
}
catch
{
Console.WriteLine("Generic Error");
return;
}
using System.Threading;
using Microsoft.ServiceBus.Messaging;
using Microsoft.WindowsAzure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ServiceBus.Messaging;
using Microsoft.WindowsAzure;
namespace AzureElasticsearchConsumer
@ThomasArdal
ThomasArdal / gist:58f781ec61ff2ffcf1635a7bc92eef07
Last active April 11, 2016 04:35
How to pin Git Shell to the taskbar (Windows 7/8)
I was looking how to pin Git Shell to the taskbar,
I got this answer from Github support (hope it can help other people) :
Hi Fabien,
Windows is annoying in that it doesn't let you pin certain items to the taskbar.
However, there is a clever way to trick it into allowing you to do this.
1) Right-click on the 'Git Shell' shortcut, click Properties and go to the 'Target' text box
2) Add the word 'explorer' in front of the line
@ThomasArdal
ThomasArdal / MyApp.cs
Last active August 22, 2022 10:08
Example of how to log all unhandled errors in a Xamarin app to elmah.io.
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Elmah.Io.Client;
using Elmah.Io.Client.Models;
namespace App5
{
[Application]
@ThomasArdal
ThomasArdal / log.php
Last active August 22, 2022 10:09
Example of how to manually log an exception from PHP to elmah.io.
// Test
function logErrorElmahIO($logID, $title, $application, $critical = '0', $detail = '', $user = '') {
$ch = curl_init();
if ($critical == '1') {
$criticalStatus = "500";
} else {
$criticalStatus = "100";
}