Skip to content

Instantly share code, notes, and snippets.

View mazhar-ansari-ardeh's full-sized avatar
🎯
Focusing

Mazhar Ansari Ardeh mazhar-ansari-ardeh

🎯
Focusing
  • Wolt
  • Berlin, Germany
View GitHub Profile
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / JsonFormatterTest.py
Last active April 5, 2018 14:10
A simple program that shows usage of the jsonlogger package.
import logging
import pythonjsonlogger.jsonlogger
import datetime
def testJsonFormatter():
supported_keys = [
'asctime',
'created',
'filename',
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / GetFileVersion.cpp
Last active April 3, 2018 11:59
A small function that retrieves file version numbers on Windows platform.
#include <windows.h>
#include <memory>
#pragma comment(lib, "version.lib")
#define ERR_INVALID_DLL_PATH 0x81000001
#define ERR_INVALID_POINTER 0x81000002
#define ERR_NAME_NOT_FOUND_OR_INVALID_RESOURCE 0x81000003
#define ERR_NO_VALUE_AVAILABLE 0x81000004
#define SUCCESS 0
std::wstring wstr = L"123";
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cv;
std::string str = cv.to_bytes(wip);
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / SampleDisposable.cs
Created January 14, 2017 07:57
A small sample that demonstrates the implementation of Dispose Pattern in C#.
using System;
class BaseClass : IDisposable
{
// Flag: Has Dispose already been called?
bool disposed = false;
// Public implementation of Dispose pattern callable by consumers.
public void Dispose()
{
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / LambdaSample.cpp
Created November 27, 2016 10:44
A small program that demonstrates the definition and usages of lambda expressions in C++.
#include <functional>
#include <iostream>
#include <stdio.h>
using namespace std;
extern function<int(int, function<int(int)>)> g;
auto f = [](int n, function<int(int)> h)
{
if (n >= 5) return n;
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / GetHBITMAPBytes.cpp
Last active November 9, 2016 10:39
The 'GetBits' function retrieves the bytes of a given HBITMAP handle. The same functionality is usually achieved with the 'GetDIBits' method of GDI. Windows CE does not support the 'GetDIBits' method. The 'GetBits' method can be improved.
#include <windows.h>
HBITMAP WINAPI GetBits(HBITMAP h, LONG width, LONG height, WORD bitCount, BYTE **bytes, DWORD *bytesLen)
{
// Sanity check omitted.
HDC hdcScreen;
hdcScreen = GetDC(NULL);
if (hdcScreen == NULL)
{
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / SampleDoxygenAnnotations.h
Last active May 8, 2018 07:18
A sample c++ header file that demonstrates the basic syntax of the Doxygen documentation.
/**
* @file SampleDoxygenAnnotations.h
* @author My Self
* @date 9 Sep 2016
* @brief File containing examples of doxygen usage for quick reference.
*
* Here typically goes a more extensive explanation of what the header
* defines. Doxygens tags are words preceeded by either a backslash @\
* or by an at symbol @@.
* @see http://www.stack.nl/~dimitri/doxygen/docblocks.html
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / SampleLog4netConfigfile.config.xml
Last active November 15, 2017 07:33
A sample config file that contains the most basic structure of a typical config file.
<!-- Save this file to as SampleLog4netConfigfile.config and load it with the following code inside the AssemblyInfo.cs file
of the project:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "SampleLog4netConfigfile.config", Watch = true)]
After this, log4net library can be used inside the project. For example, logger variables can be defined as private static
variables:
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / SamplePrint.cs
Last active September 16, 2023 00:18
A sample code that demonstrates document printing with C#
class SamplePrint
{
public bool Print(string printer)
{
if(string.IsNullOrEmpty(printer))
return false;
bool ret = false;
try
{
@mazhar-ansari-ardeh
mazhar-ansari-ardeh / SampleAESEncryptDecrypt.cs
Last active April 14, 2024 08:29
A sample code that demonstrates a typical AES Encryption/Decryption with C#
static class SampleAESEncryptDecrypt
{
static void Main()
{
string original = "The data to encrypt.";
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
{
// Setting a key size disposes the previously-set key.
// Setting a key size is redundant if a key going to be set after this statement.