Template partial specialization


#include <iostream>
#include <string>

template< class T >
class Foo;

template< class T>
class Foo< T* > {
public:
Foo( const T *t ):
t_( t ) {}
void print() const {
std::cout << *t_ << std:

Recursively clean Visual Studio SLN files

for /f "tokens=*"  %%a IN ('dir /b /s *.sln') do (
"c:Program FilesMicrosoft Visual Studio 9.0Common7IDEdevenv.exe" "%%a" /clean )

source

My lands collection

key: quantity (need/extra) colors name

*** Revised Duals
2 (2/0) UB Underground Sea
3 (1/0) UR Volcanic Island
2 (2/0) UG Tropical Island
1 (3/0) UW Tundra
2 (2/0) BR Badlands
1 (3/0) BG Bayou
1 (3/0) BW Scrubland
0 (4/0) RG Taiga
1 (3/0) RW Plateau
0 (4/0) GW Savannah

*** Shocklands
4 (0/0) UB Watery Grave
1 (3/0) UR Steam Vents
4 (0/0) UG Breeding Pool (1 foil)
4 (0/0) UW Hallowed Fountain (1 Russian)
4 (0/0) BR Blood Crypt
6 (0/2) BG Overgrown Tomb
3 (1/0) BW Godless Shrine
4 (0/0) RG Stomping Ground
4 (0/0) RW Sacred Foundry
2 (2/0) WG Temple Garden

*** Fetchlands
4 (0/0) UB Polluted Delta
6 (0/2) UR Scalding Tarn
4 (0/0) UG Misty Rainforest
3 (1/0) UW Flooded Strand
1 (3/0) BR Bloodstained Mire
4 (0/0) BG Verdant Catacombs
4 (0/0) BW Marsh Flats
1 (3/0) RG Wooded Foothills
2 (2/0) RW Arid Mesa
4 (0/0) WG Windswept Heath

*** M10 Duals
1 (3/0) UB Drowned Catacombs
0 (-/-) UR NONEXISTANT
0 (-/-) UG NONEXISTANT
4 (0/0) UW Glacial Fortress
1 (3/0) BR Dragonskull Summit
0 (-/-) BG NONEXISTANT
0 (-/-) BW NONEXISTANT
1 (3/0) RG Rootbound Crag
0 (-/-) RW NONEXISTANT
0 (4/0) GW Sunpetal Grove

*** Painlands
4 (0/0) UB Underground River
2 (2/0) UR Shivan Reef
4 (0/0) UG Yavimaya Coast
4 (0/0) UW Adarkar Wastes
4 (0/0) BR Sulfurous Springs
4 (0/0) BG Llanowar Wastes
6 (0/2) BW Caves of Koilos
5 (0/1) RG Karplusan Forest
0 (4/0) RW Battlefield Forge
5 (0/1) WG Brushland

source

IGMenustate.H

/*
	-----------------------------------------
	IGMenuState.h
	-----------------------------------------
*/

#ifndef _IGMENUSTATE_H_
#define _IGMENUSTATE_H_

#include <vector>
#include <CoreApp.h>

// IG Menu State Class
class IGMenuState : public AppState
{
public:

	// Constructor
	IGMenuState(CoreApp* core)
		: _coreApp(core)
	{}

	// Deconstructor
	~IGMenuState(){}

	// Destroy
	void destroy();

	// IG Functions
	void init();
	void update();
	void draw();
	void doInputEvents();

	// Options Creation
	void createIGMenuOptions();
	void createOptionsOptions();
	void createExitOptions();

private:

	// CoreApp Reference
	CoreApp* _coreApp;

	// Menu Options
	std::vector<irr::core::stringw> _options;

	// Asset Reference Lists
	std::vector<int> _fontRef;
	std::vector<int> _soundRef;
	std::vector<int> _surfaceRef;

	// Selected Option
	int _selectedOption;
	irr::video::SColor _optionColor;

	// Title Alpha Color
	int _titleAlpha;

	// Background Offset
	float _backgroundOffset;

	// Start Time
	float _startTime;
	bool _resetStartTime;

	// Option Enums
	enum menuOptionType
	{
		IGMENU,
		OPTIONS,
		EXIT
	};
	menuOptionType _optionType;
};

#endif

source

convert int to binary in c

#define WIDTH 32

const char *int_to_binary ( int x ) 
{ 
	static char b[WIDTH + 1] = {0};
	for (int z = WIDTH; z > 0; z--) 
	{ 
		b[z - 1] = ((1 & x) == 1) ? '1' : '0'; 
		x >>= 1; 
	}
	return b; 
}

int main() 
{ 
	unsigned int i = 0; 
	i = ~i; 
	printf("%s
", int_to_binary(i)); 
	return 0; 
}

source

rEFItBlesser

!/bin/sh

. /etc/rc.common


# Set this variable if rEFIt is installed on a different volume. You must
# make sure that the volume is mounted when the system shuts down.
MOUNTPOINT=""


MacOSXBlessed ()
{
    if bless --info | grep 'Blessed System File' | grep ' /System/Library/CoreServices/boot.efi' >/dev/null 2>&1 ; then
        return 0
    fi
    return 1
}


StartService ()
{
    if ! MacOSXBlessed ; then
        echo "rEFItBlesser blessing Mac OS X on Startup"
        bless --folder /System/Library/CoreServices --file /System/Library/CoreServices/boot.efi --setBoot
    fi
    return 0
}

StopService ()
{
    if [ -f "$MOUNTPOINT/efi/refit/refit.efi" ]; then
        if MacOSXBlessed ; then
            echo "rEFItBlesser blessing rEFIt on Shutdown"
            if [ -z "$MOUNTPOINT" ]; then
                bless --folder /efi/refit --file /efi/refit/refit.efi --labelfile /efi/refit/refit.vollabel --setBoot
            else
                bless --mount "$MOUNTPOINT" --file "$MOUNTPOINT/efi/refit/refit.efi" --setBoot
            fi
        fi
    fi
    return 0
}

RestartService ()
{
    return 0
}

RunService "$1"

source

runger Remove duplicate items from List

Set<sobject> myset = new Set<sobject>();
List<sobject> result = new List<sobject>();
myset.addAll(originalList);
result.addAll(myset);

source

Get computer MAC address

function GetMACAddress: string;
var
 AdapterList: TLanaEnum; 
 NCB: TNCB; 
begin 
 FillChar(NCB, SizeOf(NCB), 0); 
 NCB.ncb_command := Char(NCBENUM); 
 NCB.ncb_buffer := @AdapterList; 
 NCB.ncb_length := SizeOf(AdapterList); 
 Netbios(@NCB); 
 if Byte(AdapterList.length) > 0 then
   Result := GetAdapterInfo(AdapterList.lana[0]) 
 else 
   Result := 'mac not found'; 
end;

source

Get process memory usage

function GetProcessMemorySize(sProcessName: string; var nMemSize: Cardinal): Boolean;
var 
  l_nWndHandle, l_nProcID, l_nTmpHandle: HWND; 
  l_pPMC: PPROCESS_MEMORY_COUNTERS; 
  l_pPMCSize: Cardinal; 
begin 
  l_nWndHandle := FindWindow(nil, PChar(sProcessName));
  if l_nWndHandle = 0 then 
  begin 
    Result := False; 
    Exit; 
  end; 
  l_pPMCSize := SizeOf(PROCESS_MEMORY_COUNTERS); 
  GetMem(l_pPMC, l_pPMCSize); 
  l_pPMC^.cb := l_pPMCSize; 
  GetWindowThreadProcessId(l_nWndHandle, @l_nProcID); 
  l_nTmpHandle := OpenProcess(PROCESS_ALL_ACCESS, False, l_nProcID);
  if (GetProcessMemoryInfo(l_nTmpHandle, l_pPMC, l_pPMCSize)) then 
    nMemSize := l_pPMC^.WorkingSetSize
  else 
    nMemSize := 0; 
  FreeMem(l_pPMC);
  CloseHandle(l_nTmpHandle);
  Result := True; 
end; 

function GetCurrentProcessMemorySize(var nMemSize: Cardinal): Boolean;
var 
  nWndHandle, nProcID, nTmpHandle: HWND;
  pPMC: PPROCESS_MEMORY_COUNTERS;
  pPMCSize: Cardinal;
begin 
  nWndHandle := Application.Handle;
  if nWndHandle = 0 then
  begin 
    Result := False; 
    Exit; 
  end; 
  pPMCSize := SizeOf(PROCESS_MEMORY_COUNTERS);
  GetMem(pPMC, pPMCSize);
  pPMC^.cb := pPMCSize;
  GetWindowThreadProcessId(nWndHandle, @nProcID);
  nTmpHandle := OpenProcess(PROCESS_ALL_ACCESS, False, nProcID);
  if (GetProcessMemoryInfo(nTmpHandle, pPMC, pPMCSize)) then
    nMemSize := pPMC^.WorkingSetSize
  else 
    nMemSize := 0; 
  FreeMem(pPMC);
  CloseHandle(nTmpHandle);
  Result := True;
end;

source

Shutdown the (local or remote) computer (with delay)

function TimedShutDown(Computer: string; Msg: string; Time: Word; Force: Boolean; Reboot: Boolean): Boolean;
var
  rl: Cardinal;
  hToken: Cardinal;
  tkp: TOKEN_PRIVILEGES;
begin
  //get user privileges to shutdown the machine, we are talking about win nt and 2k here
  if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
    ShowMessage('Cannot open process token.')
  else
  begin
    if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then
    begin
      tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      tkp.PrivilegeCount := 1;
      AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
      if GetLastError <> ERROR_SUCCESS then
       ShowMessage('Error adjusting process privileges.');
    end
  else
    ShowMessage('Cannot find privilege value.');
  end;

  Result := InitiateSystemShutdown(PChar(Computer), PChar(Msg), Time, Force, Reboot)
end;

source