Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hadoan's full-sized avatar
🏠
Working from home

Ha Doan hadoan

🏠
Working from home
View GitHub Profile
public static class MimeTypeUtility
{
private const string OctetStream = "application/octet-stream";
private static readonly Dictionary<string, string> MimeTypesDictionary = new Dictionary<string, string>
{
{"ai", "application/postscript"},
{"aif", "audio/x-aiff"},
{"aifc", "audio/x-aiff"},
{"aiff", "audio/x-aiff"},
Server server = null;
Client client = null;
FirefoxDriver driver = null;
try
{
// Supply the path to the Browsermob Proxy batch file
server = new Server(ConfigurationManager.AppSettings["BrowserMobBatFile"], 3333);
server.Start();
client = server.CreateProxy();
@hadoan
hadoan / Log to ULS
Created January 9, 2014 08:41
Log to ULS
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("My Category", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace);
@hadoan
hadoan / ObjectDumper for C#
Last active January 2, 2016 18:59
Dumper
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Globalization;
public static void PopulateDataTypesRandom()
{
using (var package = SpreadsheetDocumentWrapper.Open("MyWorkbook.xlsx"))
{
var table = package.WorkbookPart.GetTablePart("DataTypes").Table;
var data = new List<object[]>();
for (var i = 0; i < 10; i++)
{
data.Add(new
@hadoan
hadoan / SRP1
Last active May 26, 2016 06:32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlogCode
{
public abstract class RepositoryBase<TEntity, TIDType, TLinqEntity, TContext> : IRepository<TEntity, TIDType, TLinqEntity, TContext>, IDisposable
where TEntity : AbstractBaseData<TIDType>
where TLinqEntity : EntityObject
public class DataMapper<TEntity, TIDType, TLinqEntity> : IDataMapper<TEntity, TIDType, TLinqEntity>
where TEntity : AbstractBaseData<TIDType>
where TLinqEntity : EntityObject
{
public IList<TEntity> GetEntitiesFromEF(IList<TLinqEntity> linqEntities)
{
Mapper.Initialize
(
cfg =>
{
@hadoan
hadoan / gist:747ebbeb5096bb9ebf2761578b430370
Created June 8, 2018 09:04
Backup database & migrate
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Backup database....");
Backup();
Console.WriteLine("Migrate database ...");
var config = new Configuration();
//... (set up the config object)
public class AddTodoCommand : IRequest<Guid>
{
public string Name { get; set; }
}
public class AddTodoCommandHandler : IRequestHandler<AddTodoCommand, Guid>
{
private readonly TodoDbContext _context;
public AddTodoCommandHandler(TodoDbContext context)
{
public class CompleteTodoCommand : IRequest<bool>
{
public Guid Id { get; set; }
}
public class CompleteTodoCommandHadler : IRequestHandler<CompleteTodoCommand, bool>
{
private readonly TodoDbContext _context;
public CompleteTodoCommandHadler(TodoDbContext context)
{