Skip to content

Instantly share code, notes, and snippets.

View raffacabofrio's full-sized avatar
😎
creating great solutions

Raffaello Damgaard Neves raffacabofrio

😎
creating great solutions
View GitHub Profile
@garima2510
garima2510 / CustomDbContext.cs
Last active September 16, 2020 04:28
Partial class to override SaveChanges of DbContext and use it for creating audit trail
public partial class CustomDbContext: DbContext
{
public override int SaveChanges()
{
// Get all Added/Deleted/Modified entities (not Unmodified or Detached)
//you can get updated and deleted in same collection. I am doing so for ease of purpose
//getting added entries in different collection to fetch their generated ids and then log them
var addedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();
var updatedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();
var deletedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted).ToList();
@zarxor
zarxor / ThrottleAttribute.cs
Last active January 1, 2019 21:00
Request throttling for .NET Core MVC
[AttributeUsage(AttributeTargets.Method)]
public class ThrottleAttribute : ActionFilterAttribute
{
public string Name { get; set; }
public int Seconds { get; set; }
public string Message { get; set; }
private static MemoryCache Cache { get; } = new MemoryCache(new MemoryCacheOptions());
public override void OnActionExecuting(ActionExecutingContext c)
@magegu
magegu / multipart.js
Last active July 11, 2023 20:12
mutipart upload for aws s3 with nodejs based on the async lib including retries for part uploads
/*
by Martin Güther @magegu
just call it:
uploadFile(absoluteFilePath, callback);
*/
var path = require('path');
var async = require('async');
@DanielSWolf
DanielSWolf / Program.cs
Last active April 23, 2024 20:00
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);