Wednesday, January 29, 2014
Table types in sql server
are read only
Tuesday, January 28, 2014
check time of specific parts of sp's
SELECT requests.session_id,
requests.status,
requests.command,
requests.statement_start_offset,
requests.statement_end_offset,
requests.total_elapsed_time,
SUBSTRING(details.text,
requests.statement_start_offset / 2,
(requests.statement_end_offset - requests.statement_start_offset) / 2) as problem
FROM sys.dm_exec_requests requests
CROSS APPLY sys.dm_exec_sql_text (requests.plan_handle) details
WHERE requests.session_id > 20
ORDER BY total_elapsed_time DESC
requests.status,
requests.command,
requests.statement_start_offset,
requests.statement_end_offset,
requests.total_elapsed_time,
SUBSTRING(details.text,
requests.statement_start_offset / 2,
(requests.statement_end_offset - requests.statement_start_offset) / 2) as problem
FROM sys.dm_exec_requests requests
CROSS APPLY sys.dm_exec_sql_text (requests.plan_handle) details
WHERE requests.session_id > 20
ORDER BY total_elapsed_time DESC
Thursday, January 23, 2014
special characters in blogspot
have to be encoded
e.g. <
e.g. <
Wednesday, January 22, 2014
ListView I couldnt see my columns
I was covering them with a toolbar
Linq works with IEnumerable <T >
not IEnumerable
use a cast to get LINQ on a IEnumerable<T>
use a cast to get LINQ on a IEnumerable<T>
Encrypt with File
File.Encrypt(@"c:\temp\a.txt");
File.Decrypt(@"c:\temp\a.txt");
The filename in windows turned green , the file is readable to the account that did the encryption
for some reason - the encryption tab in properties was empty
2 usings
This is a valid statement in C#
using(StreamWriter
sw = new StreamWriter(@"c:\temp\b.txt"))
using
(StreamReader sr = new
StreamReader(@"c:\temp\a.txt"))
{
sw.Write(sr.ReadToEnd());
}
Collections take IEnumerable in the constructor
Queue<string> q = new Queue<string>();
q.Enqueue("sdfsdf");
Stack<string> stack = new
Stack<string>(q);
When writeline takes an object as a parameter
it calls the
tostring method
public
class ORTostring
{
public
override string
ToString()
{
return DateTime.Now.Millisecond.ToString();
}
}
static
void Main(string[]
args)
{
Console.WriteLine(new ORTostring());
Example of IComparable and IComparer
IComparable
class
CheckCompare:IComparable<CheckCompare>
{
public
int A = 0;
public
int B = 0;
public
int C = 0;
public
int Total
{
get
{
return this.A + this.B + this.C;
}
}
public
int CompareTo(CheckCompare
other)
{
if (this.Total > other.Total)
return 1;
else if (this.Total < other.Total)
return -1;
else
return 0;
}
}
static
void Main(string[]
args)
{
List<CheckCompare> ccl = new
List<CheckCompare>();
for
(int ii = 3; ii > 0;ii--)
{
CheckCompare cc = new
CheckCompare() { A = ii, B = ii + 2, C = ii
+ 8 };
ccl.Add(cc);
}
ccl.Sort();
foreach
(CheckCompare cz in
ccl)
Console.WriteLine(cz.Total);
IComparer
public
class CheckCompareAComparer
: IComparer<CheckCompare>
{
public
int Compare(CheckCompare
x, CheckCompare y)
{
if (x.Total > y.Total)
return 1;
else if (x.Total <
y.Total)
return -1;
else
return 0;
}
}
static
void Main(string[]
args)
{
List<CheckCompare> ccl = new
List<CheckCompare>();
for
(int ii = 3; ii > 0;ii--)
{
CheckCompare cc = new
CheckCompare() { A = ii, B = ii + 2, C = ii
+ 8 };
ccl.Add(cc);
}
ccl.Sort(new CheckCompareAComparer());
foreach
(CheckCompare cz in
ccl)
Console.WriteLine(cz.Total);
Monday, January 20, 2014
How to stop a build in VS
ctrl-break
Sunday, January 19, 2014
Is this encapsulation? read only?
class
TestEncaps
{
private
List<string>
s;
public
TestEncaps()
{
s = new List<string>();
s.Add("blah");
}
public
void print()
{
Console.WriteLine(s[0]);
}
public
List<string>
S
{
get { return s; }
}
}
static
void Main(string[]
args)
{
TestEncaps
te = new TestEncaps();
te.S[0]= "blah!";
te.print();
p.s.
this is not a solution
public
List<string>
S
{
get {
string[] s2 = new string[s.Count];
s.CopyTo(s2);
return s2.ToList();
}
}
because CopyTo makes a shallow copy
Dependancy Injection
How would you pass a static class like the Console? I am not seeing good solutions out there
fatal error 823
major disk problems
Favor composition over inheritance
I guess VB6's class model wasn't so bad after all.
Friday, January 17, 2014
A left join in sql server has to be followed by left joins
otherwise it acts like a where cause
consider:
consider:
create table
#a(a int,b int ,c int)
create table
#b(a int,f varchar(100) ,g varchar(100))
create table
#c(g varchar(100),q varchar(100) ,x varchar(100))
insert into #a
values(1,4,7),(3,6,9)
insert into #b
values(1,'dsfsf','g'),(1,'wqeqe','t')
insert into #c
values('g','4','7'),('u','dfgdg','gfhfh')
select * from #a left join #b on #a.a = #b.a
left join #c on #c.g = #b.g
drop table
#a
drop table
#b
drop table #c
but
select * from #a left join #b on #a.a = #b.a
inner join #c on #c.g = #b.g
gives:
Attribute for method level security
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
public
class SecurityLevel
: Attribute
{
private
int level;
public
int Level
{
get { return level; }
set { level = value;
}
}
public
SecurityLevel(int level)
{
this.level = level;
}
public
override string
ToString()
{
string value = "Level
: " + level.ToString();
return value;
}
}
class
testSecurityLevel
{
[SecurityLevel(3)]
public
void A()
{
}
[SecurityLevel(1)]
public
void B()
{
}
}
static
void Main(string[]
args)
{
int
lev = 2;
testSecurityLevel
tsl = new testSecurityLevel();
if
(typeof(testSecurityLevel).GetMethods().Where(x
=> x.Name.Equals("A")).First().GetCustomAttributes(false).Where(x => (x as
SecurityLevel) != null).Select(x
=> x as SecurityLevel).First().Level
<= lev)
{
tsl.A();
}
if
(typeof(testSecurityLevel).GetMethods().Where(x
=> x.Name.Equals("B")).First().GetCustomAttributes(false).Where(x => (x as
SecurityLevel) != null).Select(x
=> x as SecurityLevel).First().Level
<= lev)
{
tsl.B();
}
Extension to mimic the old VB string function
public
static class BlahExtension
{
public
static char[] Space(this int cnt, char c = ' ' )
{
return
Enumerable.Repeat(c,cnt).ToArray();
}
}
public static string Space(this int cnt, char c = ' ')
{
return new string(Enumerable.Repeat('f', 10).ToArray());
}
Tuesday, January 14, 2014
Blogspot timezone
settings->language and formatting->time zone
Using HTTPS in wordpress
I used the HTTPS plugin.
I needed to set filters for an application under the wordpress site
I also checked the feature not to allow any http because I was getting mixed content messages and couldnt find the devilish source
I needed to set filters for an application under the wordpress site
I also checked the feature not to allow any http because I was getting mixed content messages and couldnt find the devilish source
Is there such a term "interface class"?
I saw it mentioned as an abstract class with no definitions. I cant find the name widely used.
C# MVC Interview Questions
- what is the vital difference between standard aspx requests and MVC requests?
- does mvc correspond to 3-tier architecture?
- why would a route need the following:
- when does the routing table get initiated?(application start event)
- what is the purpose of areas?
- can an mvc application have plain asp.net pages?
- can you use httpModules in MVC?
C# WCF Interview Questions
- Can you overload a WCF service procedure?
- Can WCF class have static procedures?
- If your class that you are using for WCF is missing a method what did you forget?
- what exactly is an endpoint?
- if you have a method in a WCF class that is void will a SOAP envelope be returned? Is there a way to have that behaviour?
- Whats is the purpose of ServiceKnownType?
In LINQ -order by and the Order By
will just use the last order by
use "ThenBy" instead
use "ThenBy" instead
Monday, January 13, 2014
Check for insecure content on https
Version in wordpress
wp-includes/version.php
Find member of array closest to 0
I saw this on a test site
my unorthodox answer:
using System;
class Solution
{
public static double ClosestToZero(double[] ts)
{
double? blah = null ;
for(int eliot=0;eliot<ts.Length;eliot++ )
{
blah = blah== null || System.Math.Abs(ts[eliot]) < blah? System.Math.Abs(ts[eliot]):blah ;
}
return (double)blah;
}
}
my unorthodox answer:
using System;
class Solution
{
public static double ClosestToZero(double[] ts)
{
double? blah = null ;
for(int eliot=0;eliot<ts.Length;eliot++ )
{
blah = blah== null || System.Math.Abs(ts[eliot]) < blah? System.Math.Abs(ts[eliot]):blah ;
}
return (double)blah;
}
}
Interesting point in covariance
passing a list<string> to a param that expects list<object> fails
but passing an object who's class is a:List<string> to a param that expects List<string> is ok
but passing an object who's class is a:List<string> to a param that expects List<string> is ok
Saturday, January 11, 2014
iis logfiles
for example \\blah\c$\inetpub\logs\LogFiles\W3SVC3
the number is based on the app id
the number is based on the app id
Friday, January 10, 2014
Error: access is denied with code 0
this could be cross - domain calls in javascript
try in chrome without security
try in chrome without security
Thursday, January 9, 2014
Factory pattern with DB objects
make sure the server (IIS) is not caching the structure of your objects if you are getting errors upon changing the sp's
Labels:
c#,
Factory Pattern,
Patterns,
sql server
varchar(MAX)
has only 8000 characters
Wednesday, January 8, 2014
Immediate invocation in Javascript
is handled, for example, thusly
(function ($) {
})(jQuery);
(function ($) {
})(jQuery);
the () is needed because otherwise JS thinks function is a decleration, the JQuery is passed in
so the code can now reference JQuery as a "$" without having to traverse the scope chain looking for the variable
Patterns in Javascript
Patterns and problems
I was reminded of patterns when I read E.O wilson's Letters to a Young Scientist that every form of life is an answer to a problem.
Here is a short list of patterns and problems they attempt to answer
Here is a short list of patterns and problems they attempt to answer
Pattern | Problem |
Singleton | Only one instance of an object |
Strategy | Apply functionality only where needed - not the whole inheritance chain |
Avoid multiple switch statements | |
Observer | Loosely coupled way to notify |
Template | force child classes to implement what they need (by making those methods abstract) , but follow the parents process |
Factory Method | Method for subclasses to create correct class |
Works in tandem with strategy | |
Abstract Factory | Defer concrtete implementation for child classes |
Avoid multiple switch statements | |
A way to have multiple versions of a class | |
Façade | Simplify gateway to single/multiple interfaces |
Command | Loosely coupled way to execute a method |
good for Qeues |
Utility to see System info over network
Cannot find proxy server (Chrome)
this should be (perhaps) unchecked
if Fiddler crashes this can be set and mess your settings- beware
Monday, January 6, 2014
To determine why SSL is failing
use tracert to get all hops and use telnet to attempt https
if the last hop fails good chance its the router not set up, as mentioned below
if the last hop fails good chance its the router not set up, as mentioned below
difference between iqueryable and ienumerable
Undefined and Defaults in Javascript
K = {};
K.T = K.T || {};
K.T.F = K.T.F || {};
the first line raises an undefined error - the other lines are ok
This and That in Javascript
var i ={
a:89,
herby:function(){
var that = this;
return function()
{
return that.a;
}
}
};
alert(i.herby()());
Mr Crockford's words on the subject are unreadable - I think the editor may have screwed up
a:89,
herby:function(){
var that = this;
return function()
{
return that.a;
}
}
};
alert(i.herby()());
Mr Crockford's words on the subject are unreadable - I think the editor may have screwed up
Sunday, January 5, 2014
htttp 502 fiddler response from https
the router was not set up properly
Friday, January 3, 2014
Connectivity testing with Ping, Telnet, Tracert and PathPing:
'telnet' is not recognized as an internal or external command,
Thursday, January 2, 2014
question on delegate predicates
in the following class:
class testLinq
{
public bool www(string s)
{ return
s.Equals("def"); }
public
delegate bool d(string s);
public
void write()
{
List<String> l = new
List<string>()
{ "abc", "def"
};
normal way of doing predicate:
Console.WriteLine(l.Find(p
=> { return p.Equals("def"); }));
bizzare method:
Predicate<string> pred = new Predicate<string>(www);
Console.WriteLine(l.Find(pred));
non working method -
d
di = null;
di = www;
Console.WriteLine(l.Find(di)));
Why?
Console.ReadLine();
}
}
Basic Web Vulnerabilities
are broken in to 3 types
- Injection
- sql injection
- LDAP Injection
- The server trusting requests
- the client trusting responses
words that c# compiler add to LINQ
for example:
in this case
in this case
SortedList<int, string> sl = new SortedList<int, string>() { {
4, "beatrice" }, { 2, "herby" } };
this
Console.WriteLine(sl.FirstOrDefault((KeyValuePair<int,
string> p) => {return
p.Key == 4; }).Value);
is equivelant to this:
Console.WriteLine(sl.FirstOrDefault(p
=> p.Key == 4).Value);
Wednesday, January 1, 2014
Subscribe to:
Posts (Atom)