Skip to content

Instantly share code, notes, and snippets.

// Un diccionari que només manté les dades X temps..
public class TemporalDictionary<T,Y> : IDictionary<T,Y> {
Dictionary<T, Y> internalDic;
Dictionary<T, DateTime> lastUpdate;
public TimeSpan ExpiringTime { get; set; }
public Y this[T key]
{
@kmteam
kmteam / SemaphoreWrapper.cs
Created July 13, 2017 10:19
using semaphore
public class SemaphoreWrapper : IDisposable
{
Semaphore _semaphore;
public SemaphoreWrapper(Semaphore Semaphore)
{
_semaphore = Semaphore;
_semaphore.WaitOne();
}
public void Dispose()
var d = 1.0d; // double
var f = 1.0f; // float
var m = 1.0m; // decimal
var i = 1; // int
var ui = 1U; // uint
var ul = 1UL; // ulong
var l = 1L; // long
http://stackoverflow.com/questions/5820721/c-sharp-short-long-int-literal-format
@kmteam
kmteam / gist:8f3106f01a11d7ca1e54ab8f981e419d
Created February 2, 2017 09:03
Pagination magic in LINQ!
var pagedItems = this.DataCollection.Skip((this.CurrentPageIndex -1) * this.ItemsPerPage).Take(this.ItemsPerPage).ToList();
@kmteam
kmteam / OpenFiles.cs
Created July 6, 2016 15:26
Use OpenFiles in Csharp
// NOTE: Require files 'ListOpenedFileDrv_32.sys' and 'OpenFileFinder.dll'
public class OpenFiles {
public enum OF_TYPE {
FILES_ONLY = 1,
MODULES_ONLY = 2,
ALL_TYPES = 3
};
public struct OF_INFO_t {
@kmteam
kmteam / gist:64a582ad7645315a20ecc645dd7ce1c5
Created June 16, 2016 07:16
Execute pice of code safely.
public static void ExecuteSafe(this Mutex MyMutex, Action myPiceOfCode)
{
try {
//while(!MyMutex.WaitOne(100)) {System.Threading.Thread.Sleep(100); }
MyMutex.WaitOne();
myPiceOfCode();
} finally {
MyMutex.ReleaseMutex();
@kmteam
kmteam / GetPrintableCurrentDate.cpp
Created March 1, 2016 13:49
Print current system date& time in ISO 8601 format
/// Print current system date& time in ISO 8601 format 2016-01-27T06:11:22Z
CString Utils::GetPrintableCurrentDate() {
SYSTEMTIME currentTime;
CString sCurrentDate;
GetSystemTime(&currentTime);
sCurrentDate.Format(_T("%04d-%02d-%02dT%02d:%02d:%02d.%03d")
,currentTime.wYear
@kmteam
kmteam / HighPassFilter.cpp
Created March 1, 2016 10:59
High pass filter
void HighPassFilter(cv::Mat &inputImage,cv::Mat &outputImage,double dSearchRatio) {
// Go float
cv::Mat fImage;
inputImage.convertTo(fImage, CV_32F);
// FFT
std::cout << "Direct transform...\n";
cv::Mat fourierTransform;
@kmteam
kmteam / TimeConsumption
Last active February 2, 2016 09:34
Mesure time Consumption of pice of code
/// <summary>
/// Mesure time compsumption of piece of code
/// </summary>
/// <param name="action">Method to test (must be a method without parameters)</param>
/// <returns></returns>private TimeSpan Mesure(Action action)
public static TimeSpan Mesure(this Stopwatch watch,Action action)
{
watch.Start();
action();