Skip to content

Instantly share code, notes, and snippets.

View jrusbatch's full-sized avatar

Justin Rusbatch jrusbatch

View GitHub Profile
internal class Job : IDisposable
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr CreateJobObject(IntPtr a, string lpName);
[DllImport("kernel32.dll")]
static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
@davidfowl
davidfowl / dotnetlayout.md
Last active November 13, 2024 13:19
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
public static class Enums
{
public static IList<dynamic> ListFrom<T>()
{
var list = new List<dynamic>();
var enumType = typeof(T);
foreach (var o in Enum.GetValues(enumType))
{
list.Add(new
@KevinT
KevinT / fullnames.csx
Created April 25, 2013 13:53
Talking to ActiveDirectory using ScriptCS. Purpose: Iterates over a file listing DOMAIN\USER credentials and spits out a file that includes their full names.
#r "System.DirectoryServices"
using System.DirectoryServices;
using System.IO;
var fullNames = new List<string>();
foreach (var credential in File.ReadAllLines("credentials.txt"))
{
if (credential.IndexOf('\\') > 0)
@shiftkey
shiftkey / duchess.md
Last active December 14, 2015 01:38
Some words about a project idea codenamed Duchess - the goal is to make a replacement for Sandcastle and make creating documentation for open source project cool again

Burn Sandcastle to the Ground

Addressing The Documentation Problem

I've had lots of discussions with people over the past few days around how open source projects in the .NET space have poor documentation (if it exists). So how do we fix this?

At a high-level, I've got these goals in mind:

  • make it easy
  • make it cool
// Struct Store
//
// Version 1: We may have written...
DocumentDatabase db = new DocumentDatabase();
User user = new User();
user.Id = 123;
user.FirstName = ....;
user.LastName = ....;
user.Bio = ....;
@briandoll
briandoll / A_toast_to_you.md
Last active March 19, 2022 01:17
Toasts! - scripts to convert images attached to GitHub issues into an animated gif for serious celebratory purposes

To toast:

  • Make sure you have ImageMagick installed (brew install imagemagick)
  • Change line 7 of toast.rb to the repository name you're working with
  • toast!
$ bundle install
$ ./get_token [user] [pass]
$ export GHUSER=[myuser]
@filipw
filipw / gist:4502859
Last active October 30, 2023 21:14
Generic EF repository
public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class, IId
{
internal DbContext Context;
internal DbSet<TEntity> DbSet;
public ICache Cache { get; set; }
public GenericRepository(DbContext context)
{
Context = context;
@khalidabuhakmeh
khalidabuhakmeh / RavenDB.cs
Created November 6, 2012 15:15
RavenDB If extension method
// usage
_db.Query<Story, Stories_Search>()
.If(status.HasValue, q => q.Where(x => x.Status == status))
.If(!curatorId.IsEmpty(), q => q.Where(x => x.CuratorId == curatorId))
.If(publicationDate.HasValue, q => q.Where(x => x.ProposedPublicationDate == publicationDate.Value.Date))
.OrderByDescending(x => x.CreatedAt)
.ToPagedList(page, size);

Assuming you have the following object:

public class Person { 
    
    public string Name { get; set; }
    public string Surname { get; set; }
    public int Age { get; set; }
}

and got a PATCH request as below: