Thursday
Navigation to the webpage was canceled chm
To fix this problem :
Right-mouse click it in Windows Explorer on chm file and select Properties. Then click Unblock.
Here is article describes the how to work around it : http://support.microsoft.com/kb/896054
Right-mouse click it in Windows Explorer on chm file and select Properties. Then click Unblock.
Here is article describes the how to work around it : http://support.microsoft.com/kb/896054
Wednesday
Strong name validation failed.
To resolve this issue run following command in Visual Studio command line:
sn -Vr "[PathToProblemDLL]\[ProblemDll].dll"
sn -Vr "[PathToProblemDLL]\[ProblemDll].dll"
Tuesday
c# extensions
//A. allows value.In("one", "two" , "tree")
public static bool In<T>(this T source, params T[] list)
{
if(null==source) throw new ArgumentNullException("source");
return list.Contains(source);
}
//#B Enable quick and more natural string.Format calls
public static string F(this string s, params object[] args)
{
return string.Format(s, args);
}
// like this one "lala {1} ".F(one, two)
//#C nice comparison tool :
public static bool Between<T>(this T actual, T lower, T upper) where T : IComparable<T>
{
return actual.CompareTo(lower) >= 0 && actual.CompareTo(upper) < 0;
}
//Allows to have :
if (myNumber.Between(3,7))
{
// ....
}
//#D a map function
public static void ForEach<T>(this IEnumerable<T> @enum, Action<T> mapFunction)
{
foreach (var item in @enum) mapFunction(item);
}
//allows to run function for every element
// like this one :
new { itemA, itemB, itemC }
.ForEach(item => {
item.Number = 1;
item.Str = "Hello World!";
});
Sunday
moving data between two list boxes +jquery
<select id="SelectLeft" multiple="multiple">
<option value="1">Australia</option>
<option value="2">New Zealand</option>
<option value="3">Canada</option>
<option value="4">USA</option>
<option value="5">France</option>
</select>
<input id="MoveRight" type="button" value=" >> " />
<input id="MoveLeft" type="button" value=" << " />
<select id="SelectRight" multiple="multiple">
</select>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(function() {
$("#MoveRight,#MoveLeft").click(function(event) {
var id = $(event.target).attr("id");
var selectFrom = id == "MoveRight" ? "#SelectLeft" : "#SelectRight";
var moveTo = id == "MoveRight" ? "#SelectRight" : "#SelectLeft";
var selectedItems = $(selectFrom + " :selected").toArray();
$(moveTo).append(selectedItems);
selectedItems.remove;
});
});
</script>
Thursday
cross platform mobile development comparison
There's a detailed comparison of all these toolkits in this article here: Modern Cross Platform Development.
There are a number of other solutions around like
Rhodes,
Titanium,
PhoneGap,
JUCE,
MoSync,
Corona and
Moai.
Each of these use a bunch different languages, including HTML5/JS/CSS, Lua, Ruby, Python and C++. All except Corona are open source and free.
There are a number of other solutions around like
Rhodes,
Titanium,
PhoneGap,
JUCE,
MoSync,
Corona and
Moai.
Each of these use a bunch different languages, including HTML5/JS/CSS, Lua, Ruby, Python and C++. All except Corona are open source and free.
Tuesday
template method design pattern c#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RulesDemo
{
/* messages */
public class MessageBase
{
public bool ClientActive { get; set; }
}
public class SPQMessage: MessageBase {
public bool Card {get;set;}
}
public class ACPMessage: MessageBase {
public bool URL {get;set;}
}
/* Ruule interface*/
public interface IRule {
string Evaluate (MessageBase messageBase);
string Evaluate (SPQMessage messageBase);
string Evaluate (ACPMessage messageBase);
}
/* rules */
/* rule base */
public class RuleBase: IRule {
public virtual string Evaluate(MessageBase messageBase)
{
throw new NotImplementedException();
}
public virtual string Evaluate(SPQMessage messageBase)
{
return Evaluate((MessageBase)messageBase);
}
public virtual string Evaluate(ACPMessage messageBase)
{
return Evaluate((MessageBase)messageBase);
}
}
/* concrete rules */
public class ClientIsActive : RuleBase
{
public override string Evaluate(MessageBase messageBase)
{
return "ClientIsActive";
}
}
public class UrlIsPresent : RuleBase
{
public override string Evaluate(ACPMessage messageBase)
{
return "UrlIsPresent";
}
}
/* */
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
list.Add(new ClientIsActive());
list.Add(new UrlIsPresent());
ACPMessage message = new ACPMessage();
foreach (IRule rule in list)
{
Console.WriteLine(rule.Evaluate(message));
}
/* this will crash because ACP rule doesn't know how to process SPQ message*/
/*
SPQMessage message2 = new SPQMessage();
foreach (IRule rule in list)
{
Console.WriteLine(rule.Evaluate(message2));
}
*/
Console.ReadLine();
}
}
}
msmq set permissions c#
private void CreateQueue(string qname)
{
try
{
if (!MessageQueue.Exists(qname))
{
MessageQueue.Create(qname);
MessageQueue messageQueue = new MessageQueue(qname);
//messageQueue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
messageQueue.SetPermissions("Local Service", MessageQueueAccessRights.FullControl);
}
}
catch (Exception e)
{
Debug.Write("Failed to setup queue:" + qname + ":" + e.ToString());
}
}
windows service installer class with event source creation
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
namespace ProcessingService
{
[RunInstaller(true)]
public partial class MyProcessorInstaller : System.Configuration.Install.Installer
{
private readonly ServiceProcessInstaller _processInstaller;
private readonly ServiceInstaller _svcInstaller;
public MyProcessorInstaller()
{
InitializeComponent();
_processInstaller = new ServiceProcessInstaller();
_svcInstaller = new ServiceInstaller();
_processInstaller.Account = ServiceAccount.LocalService;
_svcInstaller.StartType = ServiceStartMode.Automatic;
_svcInstaller.Description = "Describe here what service is doing. ";
_svcInstaller.DisplayName = "Processing Service";
_svcInstaller.ServiceName = "ProcessingService";
//Create Instance of EventLogInstaller
EventLogInstaller myEventLogInstaller = new EventLogInstaller();
// Set the Source of Event Log, to be created.
myEventLogInstaller.Source = "ProcessingService";
// Set the Log that source is created in
myEventLogInstaller.Log = "Application";
// Add myEventLogInstaller to the Installers Collection.
Installers.Add(myEventLogInstaller);
Installers.Add(_svcInstaller);
Installers.Add(_processInstaller);
}
}
}
reset sa password sql 2008
How to recover SA password on Microsoft SQL Server 2008 R2
When you are using MS SQL Server in mixed mode, it is very important that you know your SA password.
There can be different reasons you lost the password
- Person who installed the SQL Server knows the password but has left the building.
- You did not write down the password in your password file
- Password file is lost
- …
Steps to recover the SA password
-
Start SQL Server Configuration Manager
-
Stop the SQL services
-
Edit the properties of the SQL Service
-
Change the startup parameters of the SQL service by adding a –m; in front of the existing parameters
- Start the SQL services. These are now running in Single User Mode.
- Start CMD on tthe SQL server
-
Start the SQLCMD command. Now you will see following screen
-
Now we create a new user. Enter following commands
- CREATE LOGIN recovery WITH PASSWORD = ‘TopSecret 1′ (Remember SQL server has default strong password policy
-
Go
- Now this user is created
-
Now we grant the user a SYSADMIN roles using the same SQLCMD window.
- sp_addsrvrolemember ‘recovery’, ‘sysadmin’
- go
- Stop the SQL service again
-
Change the SQL service properties back to the default settings
- Start the SQL service again and use the new created login (recovery in my example)
-
Go via the security panel to the properties and change the password of the SA account.
- Now write down the new SA password.
Monday
get url c# and get url stream
public string Get(string url)
{
Debug.WriteLine(url);
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.UserAgent = GetRndUserAgent();
//This time, our method is GET.
WebReq.Method = "GET";
//From here on, it's all the same as above.
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
_log(""+WebResp.StatusCode);
_log(WebResp.Server);
//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
return _Answer.ReadToEnd();
}
public StreamReader GetStream(string url)
{
Debug.WriteLine(url);
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.UserAgent = GetRndUserAgent();
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//_log("" + WebResp.StatusCode);
//_log(WebResp.Server);
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
return _Answer;
}
jsonarray example in c#
public List<TwtAuthor> Search(string kw, int page)
{
List<TwtAuthor> ret = new List<TwtAuthor>();
string url =
string.Format(
"http://search.twitter.com/search.json?q={0}&rpp=100&include_entities=true&result_type=mixed&page{1}",kw.Replace(" ","%20"),page);
JsonObject jsonArray = JsonArray.Load(wl.GetStream(url)).ToJsonObject();
for (int i = 0; i < jsonArray["results"].Count; i++)
{
//jsonArray["results"][0]["created_at"]
TwtAuthor author = new TwtAuthor()
{
name = jsonArray["results"][i]["from_user"].ToString().Replace("\"",""),
UserID = jsonArray["results"][i]["from_user_id"].ToString(),
KwmimText = jsonArray["results"][i]["text"].ToString(),
// KwmimDate = DateTime.Parse(jsonArray["results"][i]["created_at"].ToString()), // entry.Published,
RecordCreated = DateTime.Now
};
ret.Add(author);
}
return ret;
}







