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 / PrintServerVars.cs
Last active November 29, 2022 17:14
ASP.NET MVC 4 Print server variables snippet
public class ServerVar
{
public string Key { get; set; }
public string Value { get; set; }
}
public class ServerVarsViewModel
{
public IList<ServerVar> ServerVariables { get; set; }
}
@nikanos
nikanos / add10usingbind.cpp
Last active November 29, 2022 17:14
Add 10 to all input numbers using bind2nd, bind with placeholder (C++11) and generic lambda (C++14)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
ifstream inf("input.txt");
@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,
@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 / 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 / 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 / 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]
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 / 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>
@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;