Skip to content

Instantly share code, notes, and snippets.

View NDiiong's full-sized avatar
😀
Hi there!

duong.nb NDiiong

😀
Hi there!
View GitHub Profile
@NDiiong
NDiiong / Subset.cs
Created February 2, 2021 09:34
Subset Algorithm
combine(new int[] { 1, 2, 3, 4, 5, 6 }, new List<int>(), 0);
static void combine(int[] a, List<int> outstr, int index)
{
for (int i = index; i < a.Length; i++)
{
int count = 0;
foreach (var item in outstr)
count += item;
@NDiiong
NDiiong / gist:15bb0c7788a83f479138cd825ebc1cca
Last active January 26, 2021 06:10 — forked from lafar6502/gist:8105682
some messy code of a synchronization gateway that allows only a single thread of execution for all passed callbacks. It allows new callbacks to be enqueued while they are being executed by another thread. This implementation is almost certainly broken because I didn't care if it compiles at all and if all closure stuff is done correctly, but hop…
public class ConcurrentGateway
{
private ConcurrentQueue<Action> _workQueue = new ConcurrentQueue<Action>();
private int _writeLock = 0;
[ThreadStatic]
private static AutoResetEvent _waitEvent = new AutoResetEvent(false);
protected static AutoResetEvent GetThreadWaitEvent()
{
@NDiiong
NDiiong / AsyncTask.cs
Last active January 22, 2021 06:39
AsyncTask.cs
public class AsyncTask : IDisposable
{
private readonly bool _envDTETask;
private readonly object _objlock = new object();
private readonly TaskFunction _taskFunction;
private readonly Thread _thread;
@NDiiong
NDiiong / Wildcard.cs
Last active January 22, 2021 05:48
Wildcard.cs
//https://www.geeksforgeeks.org/wildcard-character-matching/
//https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.wildcardpattern.containswildcardcharacters?view=powershellsdk-7.0.0
public class Wildcard
{
private readonly string _pattern;
public Wildcard(string pattern)
{
_pattern = pattern;
}
@NDiiong
NDiiong / EncodingDetector.cs
Created January 21, 2021 12:54
Detect Encoding ANSI
public static bool ANSI(string filename)
{
var file_stream = File.OpenRead(filename);
if (file_stream == null) return false;
var stream = new BinaryReader(file_stream);
var file_size = file_stream.Length;
byte[] buffer = new byte[file_size];
stream.Read(buffer, 0, (int)file_size);
stream.Close();
@NDiiong
NDiiong / PdfDocument.cs
Created December 4, 2020 10:52
Helper PdfDocument support for libary itextsharp
public static class PdfDocument
{
public static void AddRange(this Document document, IEnumerable<IElement> elements)
{
elements.ForEach(f => document.Add(f));
}
public static byte[] Concat(IEnumerable<byte[]> documents)
{
Guard.NotNullOrZeroLength(documents, nameof(documents));
@NDiiong
NDiiong / RockSolidChurchTemplate.cs
Created November 16, 2020 08:22 — forked from tcavaletto/RockSolidChurchTemplate.cs
Rock Solid Church Template
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using com.centralaz.RoomManagement.Attribute;
using com.centralaz.RoomManagement.Model;
using com.centralaz.RoomManagement.ReportTemplates;
using iTextSharp.text;
using iTextSharp.text.pdf;
@NDiiong
NDiiong / Quartz : Tables Sql Server
Last active November 11, 2020 04:55
quartz config
-- this script is for SQL Server and Azure SQL
--https://raw.githubusercontent.com/quartznet/quartznet/master/database/tables/tables_sqlServer.sql
USE [enter_db_name_here];
GO
IF OBJECT_ID(N'[dbo].[FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS]', N'F') IS NOT NULL
ALTER TABLE [dbo].[QRTZ_TRIGGERS] DROP CONSTRAINT [FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS];
GO
public static class CollectionServiceExtension
{
public static IServiceCollection Registers<TService>(this IServiceCollection services, ServiceLifetime lifetime, params Assembly[] assemblies)
where TService : class
{
return services.Registers(lifetime, assemblies, typeof(TService));
}
public static IServiceCollection Registers(this IServiceCollection services, ServiceLifetime lifetime, Assembly assemblies, params Type[] interfaceTypes)
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace DomainServices
{
public class DataBuilder<TIn, TOut> where TIn : class where TOut : class, new()
{