Skip to content

Instantly share code, notes, and snippets.

View nikanos's full-sized avatar

Nikanos Polykarpou nikanos

  • ::1, Nicosia, Cyprus
View GitHub Profile
@nikanos
nikanos / app.config
Last active October 31, 2022 20:07
.NET Configuration file - network tracing
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- config sections -->
</configSections>
<system.diagnostics>
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
@nikanos
nikanos / web.config
Last active October 31, 2022 20:08
IIS URLRewrite Rule - Remove Port From ForwardedFor Header
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- config sections -->
</configSections>
<system.webServer>
<rewrite>
<rules>
<rule name="Remove Port From ForwardedFor Header">
<match url="(.*)" />
@nikanos
nikanos / GetRemoteIP.cs
Last active October 31, 2022 20:05
GetRemoteIP - extension method on HttpRequestBase
public static string GetRemoteIP(this HttpRequestBase request, bool useForwardedForHeader = false)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
const string FORWARDED_FOR = "HTTP_X_FORWARDED_FOR";
const string REMOTE_ADDR = "REMOTE_ADDR";
string ipAddress = null;
@nikanos
nikanos / app.config
Created October 4, 2021 08:46
.NET Configuration file - IIS Request size & time limits
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- config sections -->
</configSections>
<system.web>
<!-- 20 MB max. request, 1800s (30min) timeout -->
<httpRuntime maxRequestLength="20480" executionTimeout="1800" />
</system.web>
</configuration>
USE DATABASE_NAME
DECLARE @SearchStr nvarchar(100) = 'SEARCH_TEXT'
DECLARE @Results TABLE (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
@nikanos
nikanos / MSTestDataTestMethodSample.cs
Last active October 31, 2022 20:01
MSTest DataTestMethod & DataRow example
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace MSTestDataTestMethodSample
{
[TestClass]
public class NumberCheckerTests
{
[TestMethod]
[DataTestMethod]
@nikanos
nikanos / ShowErrorMessage.cpp
Last active October 31, 2022 20:38
C++ ellipsis example - Windows ShowErrorMessage
void ShowErrorMessage(const char* format, ...)
{
va_list argp;
va_start(argp, format);
vShowErrorMessage(format, argp);
va_end(argp);
}
void vShowErrorMessage(const char* format, va_list argp)
{
@nikanos
nikanos / SignedXmlWithReferenceIdAttributeName.cs
Created November 1, 2022 12:04
SignedXmlWithReferenceIdAttributeName - class inherited from SignedXml that gives the option to specify the name of the id attribute when signing XML
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Xml;
namespace NS
{
class SignedXmlWithReferenceIdAttributeName : SignedXml
{
private string _referenceIdAttributeName;
@nikanos
nikanos / winproclist.c
Last active November 2, 2022 10:10
Windows Process List - Win32 code in C to retrieve the list of the processes using the CreateToolhelp32Snapshot() function
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
void PrintHeader()
{
_tprintf(TEXT("%10s %40s\n"), TEXT("Process ID"), TEXT("Process Name"));
}
void PrintProcessEntry(PROCESSENTRY32 pe)
@nikanos
nikanos / nomovewin.c
Created November 4, 2022 22:12
C Win32 snippet to create a non-movable window by handling the WM_MOVING message
#include <windows.h>
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
TCHAR WinClassName[] = TEXT("NoMoveWinClass");
int WINAPI WinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,