Thursday

C# example:how to get version/created time of assembly

1, We need function like this :
  public string GetServerInfo(Assembly _assembly)
{
StringBuilder r = new StringBuilder();
try
{
r.AppendLine("Version:" + _assembly.GetName().Version.ToString());
r.Append("Build: " + System.IO.File.GetLastWriteTime(_assembly.Location).ToString("dd/MM/yyyy HH:mm"));
}
catch (Exception ex)
{
Logger.prn(ex);
}
return r.ToString();
}


Then we can call it like this :

Assembly _assembly = Assembly.GetExecutingAssembly();
string info= GetServerInfo(_assembly);

Sunday

mysql how to select records with unicode characters

following select returning these records:
SELECT * FROM candidate WHERE CHAR_LENGTH(first_name)<>LENGTH(first_name);


mysql and php to fix character encoding

*  call mb_internal_encoding("UTF-8") at the head of my PHP scripts
*  MySQL tables all have DEFAULT CHARSET=utf8  > COLLATE=utf8_unicode_ci
*  call mysql_set_charset('utf8') immediately after I connect to the  DB with mysql_connect().
*  call header('Content-Type: text/html; charset=utf-8') before  outputting anything to the browser.
*  specify <meta http-equiv="Content-Type" content="text/html;  charset=utf-8"/> in the HEAD of my HTML.
*  FORM tags all have accept-charset="UTF-8".



Friday

vim commands

:g/search-string/norm @h  
runs a macro recorded in h for every match of search-string

Vim-style movement:
'h' 'j' 'k' 'l' for movement (Up, Down, Left, Right)
'gg' End
'G' Home
'0' Beginning of line
'$' End of Line
'H' Top of the Screen
'M' Middle of the screen
'L' Bottom of the screen

windows using
:split command or the ^w commands:

^wn - new window

^ws - horizontal split

^wv - vertical split

^wr - rotate windows

^ww/^wW - move to the next/previous window

^w= - make all windows equal size

^wc - close the active window




Tuesday

Load controls in asp.net dynamically

1.Add placeholder to .aspx
<asp:Panel ID="PlaceHolderPanel" runat="server">
</asp:Panel>

2. add control loading code to codebehind :
string AlreadyLoaded=null;
private void loadControl(string ctr){
if (!string.IsNullOrEmpty(ctr) && AlreadyLoaded!=ctr ) {
Control ctrl = LoadControl(ctr);
ctrl.ID="ctr1";
PlaceHolderPanel.Controls.Clear();
PlaceHolderPanel.Controls.Add(ctrl);
ControlName = ctr;
AlreadyLoaded=ctr;
}

}

protected void Page_Load(object sender, EventArgs e){
loadControl("~/Controls/mycontrol.ascx");
}


There are limitations for loaded controls , one of them using onPreRender rather then Page_load:

// 1.call all functions in prerender only
protected override void OnPreRender(EventArgs e){
SetFilterValues();
Bind();
base.OnPreRender(e);
}

Saturday

C# how to use iterator


// create iterator method

public IEnumerable<decimal?> BucketIterator(Accounts_basic a ) {
int cycle = 0;
for (int i=7 ; i > 0 ; i--){

switch (i) {
case 1:yield return a.dd_15;break;

case 2 :yield return a.dd_30; break;

case 3:yield return a.dd_60; break;

case 4:yield return a.dd_90; break;

case 5 :yield return a.dd_120; break;

case 6:yield return a.dd_150; break;

case 7:yield return a.dd_180; break;

default : yield break;

}

}



// use iterator method as follows
foreach (decimal? amount in BucketIterator(accounts_basic)) {
// use amount here
}

Stored User Names and Passwords

to retrieve a list of Stored User Names and Passwords do:
C:>rundll32.exe keymgr.dll, KRShowKeyMgr

Windows can store your logon information for network locations and Web sites. To add an entry, click Add. To edit an existing entry, select it, and then click Properties.


is already mapped in workspace or removing other's working space

The path C:\Projects is already mapped in workspace PC123;DOMAIN\USER

tf workspaces /computer:PC123 /owner:* /format:detailed

And – sure enough, it looks like there’s another workspace for a different user profile – with the same PC name (PC123).
tf workspaces /computer:PC123 /owner:* /format:detailed /server:http://tfs:8080
================================
Workspace: PC123
Owner : *ME*
Computer : PC123
Comment :
Server : tfs.domain
Working folders:
====================================
Workspace: PC123
Owner : *SOMEONE-ELSE*
Computer : PC123
Comment :
Server : tfs.domain

Working folders:
$/AAA: C:\Projects
$/AAA/BBB/CCC: C:\Projects\AAA\BBB\CCC
Not sure how/why this has happened – perhaps a duplicate PC-NAME ?

Anyway – here’s the command to REMOVE the baaad workspace – clear it out all and start again.

tf workspace /delete PC123;other-user /server:http://tfs:8080
A deleted workspace cannot be recovered.
Workspace ‘PC123′ on server ‘http://tfs.8080′ has 0 pending change(s).
Are you sure you want to delete the workspace? (Yes/No) Y



Friday

vim commands

:e . Открыть встроенный файл-менеджер
:Sex Разбить окно и открыть встроенный файл менеджер
:browse e Графический файл-менеджер
:ls Список буферов
:cd .. Перейти в родительскую директорию
:args Список открытых файлов

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...