My online notes – Section 0007

Note 16: Kingston New Year USB Code
DTCNY16 : Year of monkey

Dtcny16

Note 15: Kingston New Year USB Code
DTCNY15 : Year of Goat

Dtcny15

DTCNY14 : Year of Horse

DTCNY14 Year of Horse Kingston USB

Dtcny14 Year of Horse Kingston USB

DTCNY13 : Year of Snake

DTCNY13

DTCNY12 : Year of Dragon

DTCNY12

Note 1: Execute file bat under administrator
Create an other .bat file to run the .bat file with command

runas /u:administrator /savecred thesecond.bat

Note 2: SetThreadExecutionState is used to stop the machine timing out and entering standby/switching the display device off.

[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);

[FlagsAttribute]
public enum EXECUTION_STATE :uint
{
     ES_AWAYMODE_REQUIRED = 0x00000040,
     ES_CONTINUOUS = 0x80000000,
     ES_DISPLAY_REQUIRED = 0x00000002,
     ES_SYSTEM_REQUIRED = 0x00000001
     // Legacy flag, should not be used.
     // ES_USER_PRESENT = 0x00000004
}

 void PreventMonitorPowerdown ()
{
	SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
}

void AllowMonitorPowerdown ()
{
	SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}

void PreventSleep ()
{
	// Prevent Idle-to-Sleep (monitor not affected) (see note above)
	SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
}

void KeepSystemAwake ()
{
	SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
}

Note 3: ListView Background Color Alternating

public sealed class BackgroundConverter : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		ListViewItem item = (ListViewItem)value;
		if (((Person)item.DataContext).Height < 1.5)
			return Brushes.AliceBlue;
		if (((Person)item.DataContext).Height >= 1.75)
			return Brushes.Aqua;
		else
			return Brushes.AntiqueWhite;
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}
}

...

public List<Person> PersonList
{
	get
	{
		return new List<Person>()
		{
			new Person{Name="C",Height=1},
			new Person{Name="A", Height=1.5},
			new Person{Name="B", Height=2},
			new Person{Name="D",Height=1.25},
			new Person{Name="E",Height=1.75},
			new Person{Name="F",Height=1.125},
			new Person{Name="F",Height=1.375},
			new Person{Name="G",Height=1.625},
			new Person{Name="H",Height=1.875},
		};
	}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:c="clr-namespace:ListView_Background_Color_Alternating.Converter">
	<c:BackgroundConverter x:Key="CustomBackgroundConverter"></c:BackgroundConverter>
	<Style TargetType="{x:Type ListViewItem}">
		<Setter Property="Background">
			<Setter.Value>
				<Binding RelativeSource="{RelativeSource Self}" Converter="{StaticResource CustomBackgroundConverter}" />
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>
<ListView ItemsSource="{Binding PersonList}">
	<ListView.View>
		<GridView>
			<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
			<GridViewColumn Header="Height" DisplayMemberBinding="{Binding Height}"/>
		</GridView>
	</ListView.View>
</ListView>

Note 4: RichTextBox filter row

public static void DeleteLinesFromRTB(RichTextBox rtb, string searchString)
{
	// Find first position of the searchString.
	TextPointer tp = FindWordFromPosition(rtb.Document.ContentStart, searchString);

	while (tp != null)
	{
		// If searchString was found.

		// Determine the offset for the first instance of the new line char before the current text pointer.
		TextRange tempRange = new TextRange(rtb.Document.ContentStart, tp);
		int lastNewLineSymbolIndex = tempRange.Text.LastIndexOf('\r');
		int beginLineSymbolOffset = tempRange.Text.Length - lastNewLineSymbolIndex;

		// Define the complete line text range.
		TextRange myRange = new TextRange(
			tp.GetPositionAtOffset(beginLineSymbolOffset * (-1)), // Inverting the index.
			tp.GetPositionAtOffset(tp.GetTextRunLength(LogicalDirection.Forward)));

		// Deleting the complete line.
		myRange.Text = string.Empty;

		// Rescan the rtb content for further instances of searchString.
		tp = FindWordFromPosition(rtb.Document.ContentStart, searchString);
	}
}

public static TextPointer FindWordFromPosition(TextPointer position, string word)
{
	while (position != null)
	{
		if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
		{
			string textRun = position.GetTextInRun(LogicalDirection.Forward);

			// Find the starting index of any substring that matches "word".
			int indexInRun = textRun.IndexOf(word);
			if (indexInRun >= 0)
			{
				position = position.GetPositionAtOffset(indexInRun);
				break;
			}
		}

		position = position.GetNextContextPosition(LogicalDirection.Forward);
	}

	// position will be null if "word" is not found.
	return position;
}

Note 5: Wisedock ref link
http://www.wisedock.de/user.php?rf=DE15174

Homepage 1: http://www.wisedock.de/m.php?id=15174ffafd267d2df2010c39e6099fbb74fcc
Homepage 2: http://www.wisedock.de/m.php?id=2043067345e505b41f06a58f6ceb3a76f4b9c

Note 6: Configure firewall with cmd

netsh firewall set opmode mode=disable interface

Deactivate firewall for LAN connection

add allowedprogram C:\\Programm.exe "Testprogramm" ENABLE

Insert to white list of firewall. “DISABLE” is for blocking programm through firewall.

add portopening TCP 80 "Webport" ENABLE

Open port with “ENABLE”, use “DISABLE” to close port.

Use “netsh firewall /?” and “netsh advfirewall /?” to see more options.

Note 7: FormatWith 2.0

public static string FormatWith(this string format, object source)
{
  return FormatWith(format, null, source);
}

public static string FormatWith(this string format, IFormatProvider provider, object source)
{
  if (format == null)
    throw new ArgumentNullException("format");

  Regex r = new Regex(@"(?<start>\{)+(?<property>[\w\.\[\]]+)(?<format>:[^}]+)?(?<end>\})+",
    RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

  List<object> values = new List<object>();
  string rewrittenFormat = r.Replace(format, delegate(Match m)
  {
    Group startGroup = m.Groups["start"];
    Group propertyGroup = m.Groups["property"];
    Group formatGroup = m.Groups["format"];
    Group endGroup = m.Groups["end"];

    values.Add((propertyGroup.Value == "0")
      ? source : DataBinder.Eval(source, propertyGroup.Value));

    return new string('{', startGroup.Captures.Count) + (values.Count - 1) + formatGroup.Value + new string('}', endGroup.Captures.Count);
  });

  return string.Format(provider, rewrittenFormat, values.ToArray());
}

Use it:

var student = new
{
  Name = "John",
  Email = "john@roffle.edu",
  BirthDate = new DateTime(1983, 3, 20),
  Results = new[]
  {
    new { Name = "COMP101", Grade = 10 },
    new { Name = "ECON101", Grade = 9 }
  }
};
Console.WriteLine("Top result for {Name} was {Results[0].Name}".FormatWith(student));
// "Top result for John was COMP101"

Note 8: VMWare Workstation 8.0.3 serial key
NY4ZJ-2D00N-2ZDY8-QTA5P-C2UJ2

Note 9: Value Type vs Reference Type
A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.
Value Types
Value types include the following:
– All numeric data types
– Boolean, Char, and Date
– All structures, even if their members are reference types
– Enumerations, since their underlying type is always SByte, Short, Integer, Long, Byte, UShort, UInteger, or ULong

Reference Types
Reference types include the following:
– String
– All arrays, even if their elements are value types
– Class types, such as Form
– Delegates

Elements That Are Not Types
The following programming elements do not qualify as types, because you cannot specify any of them as a data type for a declared element:
– Namespaces
– Modules
– Events
– Properties and procedures
– Variables, constants, and fields
– Working with the Object Data Type

You can assign either a reference type or a value type to a variable of the Object data type. An Object variable always holds a pointer to the data, never the data itself. However, if you assign a value type to an Object variable, it behaves as if it holds its own data. For more information, see Object Data Type.

You can find out whether an Object variable is acting as a reference type or a value type by passing it to the IsReference method on the Information class in the Microsoft.VisualBasic namespace. Microsoft.VisualBasic.Information.IsReference(System.Object) returns True if the content of the Object variable represents a reference type.

Note 10: Windows – Disappearing System Tray Icons Fix
Run this bat script : http://hintdesk.com/Web/Tool/FixSystemTrayIcon.bat

Note 11: How to: Use Special Characters in XAML
http://msdn.microsoft.com/en-us/library/aa970677.aspx

Note 12: IE 10 – Set download folder
– Go to Tool -> View downloads (or press Ctrl-J)

View downloads

– Click on options

Download folder Options

– Set new download folder through Browse button

Set download folder IE 10

Note 13: Generate client class from WCF service

http://msdn.microsoft.com/de-de/library/vstudio/ms751423%28v=vs.90%29.aspx

Note 14: Folder image like in Windows Explorer
Use Windows API Code Pack for Microsoft .NET Framework

var myShellFile = ShellFile.FromFilePath(myFilePath);
var myShellPic = shellFile.Thumbnail.ExtraLargeBitmap;

Note 16: Samsung DUOS S7652 USB Driver
https://mega.co.nz/#!W1ZjGSia!FLpRw3S-poDwGmWfycLQ31_ILm1ZD5jaoSgEkO8yrAA

Note 17: Activate Telnet under Windows
pkgmgr /iu:”TelnetClient”

Note 18: MS SQL Update from Select
@”UPDATE #REPLACE_WITH_SCHEMA#FILES
SET #REPLACE_WITH_SCHEMA#FILES.SORT = SUBQUERY.SORT
FROM
(
SELECT (ROW_NUMBER() OVER(ORDER BY SOURCETIMESTAMP DESC)) AS SORT, ID FROM #REPLACE_WITH_SCHEMA#FILES
)SUBQUERY
INNER JOIN #REPLACE_WITH_SCHEMA#FILES ON SUBQUERY.ID = #REPLACE_WITH_SCHEMA#FILES.ID”

Note 19: Search Vietnamese Unicode (or other language with special Latin characters) in SQLite database
For example, search for “hải sơn” should be like this
SELECT * FROM towns WHERE title COLLATE utf8_general_ci LIKE ‘%hai son%’;

Note 20: Backtrack bt login
Default username and password of Backtrack are ‘root’ and ‘toor’. Use ‘startx’ to go to UI.

Leave a Reply

Your email address will not be published. Required fields are marked *