Multi level generics in C#

To create multi level generic inheritance in C3 following structure could be used:

// top most inheritance level
public class TopLayer: MidLayer<TopLayer>
{
	// Your code goes here
}

// internal layer
public class MidLayer<T>: BaseLayer<T> where T: MidLevelLayer<T>, new ()
{
	// Your code goes here
}

// base layer
public class BaseLayer<T> : IBaseObject, new()
{
	// Your code goes here
}

// (optional) Interface
public interface IBaseObject
{
	// Your code goes here
}

Simple self restartable windows service

To make a self restartable service simple cmd script may be used.
Code is in C#:

private void RestartSrv()
{
	_log.Debug($"RestartSrv()");
	try
	{
		var name = "SomeServiceName";

		var f = @"C:\restart.cmd"; // put this somewhere

		_log.Trace($"creating {f}");

		var cmd = new string[]
		{
			"@ECHO OFF",
			$"net stop {name}",
			"PING -n 20 127.0.0.1 > NUL",
			$"net start {name}",
		};

		File.WriteAllLines(f, cmd, Encoding.ASCII);

		_log.Trace($"launching {f}");
		var nfo = new ProcessStartInfo(f);
		Process.Start(nfo);
	}
	catch (Exception ex)
	{
		_log.Error(ex, "RestartSrv()");
	}
	
}

Kill windows service

To kill windows service forcefully:

C:\WINDOWS\system32>sc queryex "Bonjour Service"

SERVICE_NAME: Bonjour Service
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 2688
        FLAGS              :

C:\WINDOWS\system32>taskkill /F /PID 2688

Multiline PostgresSQL data migration on Windows Cmd

Multiline table migration migration on windows cmd for PostgreSQL

Tables matches

psql -U USERNAME -h localhost -d DATABASE ^
-c "copy (SELECT * FROM customer_modules) to stdout with csv" | ^
psql -U USERNAME -h localhost -p 5433 -d DATABASE ^
-c "copy customer_modules from stdin csv"

Tables columns doesnt match

psql -U USERNAME -h localhost -d DATABASE ^
-c "copy (SELECT * FROM assignments WHERE id_over_slot_price_rate !=1) to stdout with csv" | ^
psql -U USERNAME -h localhost -p 5433 -d DATABASE ^
-c "copy assignments (id_assignment, id_ltc_group, id_component, slots, deleted, id_std_price_rate, id_over_slot_price_rate, discount, id_customer, id_users_log) from stdin csv"

Centos 7 Network Manager

Problem NetworkManager controlled network doesn’t reload configuration after:
systemctl restart network
Solution:
nmcli d status
nmcli d connect eth0

check if address changed:
ip addr show

Visų windows servisų sąrašas

jei reikia sužinoti visus servisus ir jų statusus per komandinę eilutę (tarpai būtini):

    sc queryex type= service state= all

jei reikia surasti servisą:

    sc queryex type= service state= all | find /i "serviso_pavadinimas"

find /i nekreipiam dėmesio į raidžių dydžius
Šaltinis

Tikrinam kiek RAM ir kokie slotai užimti Windos OS

Kaip pasitikrinti kiek RAM Windows OS ir kuriuose slotuose jis yra?

cmd
wmic MEMORYCHIP get banklabel, capacity, caption, devicelocator, partnumber

PowerShell
Get-WmiObject -Class Win32_PhysicalMemory | fl BankLabel, Capacity, DeviceLocator, PartNumber, SerialNumber, PositionInRow, Speed, Tag

Simple disk maps with NET USE

  • To check all mapped drives:
  • C:\Users\user>net use
    New connections will be remembered.
    Status Local Remote Network
    -------------------------------------------------------------------------------
    OK P: \\192.168.1.2\personal Microsoft Windows Network
    The command completed successfully.

  • To map a network shared drive:
  • C:\Users\user>net use p: \\192.168.1.2\personal /user:username@domain.local

  • To delete
  • C:\Users\user>net use \\192.168.1.2\personal /delete
    Deletes single shared folder

    C:\Users\user>net use * /delete
    Deletes all connections

if CMD is runing as Administrator disk will be mapped for administrator.

Zimbra ZCS raudoni X

Švariai suinstaliuotoj zimbroj norint sutvarkyti serverio statuso problemą reikia:

[root@jmail ~]# ls -l /var/spool/cron/zimbra
-rw-------. 1 zimbra root 3535 Sep 17 12:30 /var/spool/cron/zimbra
[root@jmail ~]# chown zimbra.zimbra /var/spool/cron/zimbra

Lietuviška Centos repozitorija

Paskutiniu metu tenka dažnai dirbti su Centos OS, todėl prireikė susirasti lietuvišką centos repozitoriją sistemos instaliavimui per http protokolą.

Veidrodžių statusas:

http://mirror-status.centos.org/#lt

Lietuviškas veidrodis:

http://mirror.duomenucentras.lt

Taip pat gyvenimo palengvinimui pridedam EPEL repozitorija

CentOS 6.x 64-bit (x64):

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm

Fedoros DUK jei pasikeitė versija:
http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F