Skip to content

Instantly share code, notes, and snippets.

View derekantrican's full-sized avatar

Derek Antrican derekantrican

View GitHub Profile
@derekantrican
derekantrican / FreshDesk.cs
Last active January 5, 2021 21:49
A modified version of the FreshDesk C# API sample for creating a ticket with an attachment: https://github.com/freshdesk/fresh-samples/blob/master/C-Sharp/CreateTicketWithAttachment.cs
/*----------------------------------------------------------------------------------------------------------
* THIS CLASS DEPENDS ON THE FOLLOWING:
* System.Web.Extensions reference
* MimeTypeMap.List nuget package (https://www.nuget.org/packages/MimeTypeMap.List/)
*
*
* ALSO: do not forget to fill in your FreshDesk domain and FreshDesk API (lines 23 & 24)
* ----------------------------------------------------------------------------------------------------------
*/
using System;
@derekantrican
derekantrican / SplitButton.cs
Last active October 24, 2019 15:52
A simple split button for C# WinForms
using System;
using System.Windows.Forms;
using System.Drawing;
namespace SplitButton
{
public class SplitButton : Button
{
public ContextMenuStrip SplitMenuStrip = new ContextMenuStrip() { ShowImageMargin = false };
private string currentText;
@derekantrican
derekantrican / GCalAPIHelper.cs
Last active August 18, 2019 17:31
Exponential Backoff with Google Calendar API
using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.IO;
using System.Linq;
using System.Net;
@derekantrican
derekantrican / SalvageXML.cs
Last active October 24, 2019 15:52
An example about how to salvage an XML file when it is improperly formatted
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Xml.Serialization;
@derekantrican
derekantrican / NumberWordsToNumbers.cs
Last active March 15, 2020 00:51
A class for converting number words (eg "I am ninety-seven years old") in a string into their numerical representation (eg "I am 97 years old")
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace NumberWordsToNumbers
{
/* ==================================================================================================
* A robust class for converting a number words (eg "one-hundred and sixty-nine") in a string
@derekantrican
derekantrican / FTPHelper.cs
Last active May 3, 2020 03:29
Retrieve directory listing information from FTP
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
namespace FTPHelper
{
@derekantrican
derekantrican / Timeout.cs
Last active July 28, 2020 03:30
Add a timeout to any section of C# code
using System.Threading;
//USAGE:
//using (Timeout timeout = new Timeout(TimeSpan.FromSeconds(5), "This code timed out!"))
//{
// SomeLinesOfCodeThatYouWantToCheck...
//}
public class Timeout: IDisposable
{
@derekantrican
derekantrican / Program.cs
Created September 17, 2020 17:05
C# console app to set Windows background image and lockscreen image (REQUIRES ADMIN PERMISSIONS)
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace LockScreen
{
/* ====================================================
*
@derekantrican
derekantrican / Program.cs
Created September 17, 2020 17:40
C# console app to set the top-most picture on a subreddit to the Windows lock screen
using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Newtonsoft.Json.Linq;
namespace SubredditLockscreen
{
class Program
@derekantrican
derekantrican / Program.cs
Last active December 23, 2020 01:22
A template for a Reddit Bot written in C# using RedditSharp
using RedditSharp;
using RedditSharp.Things;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;