works because this works
(function (a) {alert(a);})("kl")
Monday, December 1, 2014
Thursday, November 20, 2014
the world is really cyclical
the dynamic keyword in c# and old VB
Wednesday, November 12, 2014
app cmd script to allow ipv4 access on iis
%systemroot%\system32\inetsrv\AppCmd.exe set config "blah/subblah" /section:ipsecurity /+"[ipaddress='105.536.551.514',allowed='true']" /commit:appHost
Thursday, October 30, 2014
c# threading questions
- does a blocked thread use CPU resources?
Thursday, October 2, 2014
today I discovered that there is in sql
a switch to statement
Tuesday, September 30, 2014
object_id with table created by mistake with schema name
OBJECT_ID(N'blah.[blah.boo]')
brackets around the whole name worked
brackets around the whole name worked
Monday, September 22, 2014
Could not load type MvcApplication
just restarted VS
Friday, September 19, 2014
varchar(max) > 4000 characters
only with casting
Wednesday, September 17, 2014
asynchronous <> multithreaded
changing recovery plan
I coudnt do it with the graphical tools because the log was full
this worked
ALTER DATABASE blah set recovery simple
this worked
ALTER DATABASE blah set recovery simple
Tuesday, September 16, 2014
DBCC SHRINKFILE
uses the logical name
Wednesday, September 10, 2014
object_id needs the schema
ouch and duh
GO's Kill variables
I learned the hard way
An aggregate may not appear in the set list of an UPDATE statement
i just used a CTE
wireless mouse
can be impacted by objects like a phone or keyboard in between computer and mouse
Tuesday, September 9, 2014
" works like [ in sql server
create table xxxxxx ("x x" int)
insert into xxxxxx values (456)
select [x x] from xxxxxx
select "x x" from xxxxxx
insert into xxxxxx values (456)
select [x x] from xxxxxx
select "x x" from xxxxxx
Monday, September 8, 2014
sql server computed column with case
blah as case when ...
Thursday, August 28, 2014
exec in Team City
you need to add exec - for example - a plain sp_rename wont work
TFS Woes
a changeset can have a reference to a file that has been renamed and will leave you in the dark that that has happened.
Wednesday, August 27, 2014
sql bracket woes
an example of nightmares in brackets:
IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[xx]') AND type in (N'U'))
drop table xx
go
create table x (x int)
EXEC sp_rename '[dbo].[x]', '[dbo].[xx]';
IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[[dbo]].[xx]]]') AND type in (N'U'))
EXEC sp_rename '[dbo].[[dbo]].[xx]]]',
'xx';
GO
sp_rename woes
do not include the scheam in the 2nd parameter!
keep "[" away from the name
keep "[" away from the name
Friday, August 22, 2014
cross apply vs join on aggregate
thought this was great
Wednesday, August 20, 2014
“ASP.NET Web pages with Razor syntax 3.0.0.0″
All and Bubbling
Using the all selector, you can bubble on events thusly: $('*').on('click', function () {
Thursday, July 10, 2014
Friday, June 13, 2014
New Laptop blues VS - bad filename or volume name
difficult week
finally got it - cleared workspaces (including remote) and downloaded everything again
finally got it - cleared workspaces (including remote) and downloaded everything again
Tuesday, June 10, 2014
provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
the version of project was wrong so the references were not being created
Friday, May 30, 2014
web installer hung
i ran reset from command line
installing mvc 4
on vs 2012 kept on failing because of a lack of a patch on vs 2010 (huh?)
i installed mvc 3 first and all was good
i installed mvc 3 first and all was good
Thursday, May 29, 2014
Monday, May 19, 2014
only date in javascript
var curdate = new Date();
curdate.setHours(0,0,0,0);
curdate.setHours(0,0,0,0);
Wednesday, May 14, 2014
when to use x86 on a VS build
I needed that for creating an exe that had to work on 64 bit bit still had references to 32 bit
How to copy a distribution list for an outlook meeting invite
the easiest way I found was to reply to the earlier meeting to get the list of names and copy
Tuesday, May 13, 2014
adding existing files to vs project
dont add the designer just the plain cs
Monday, May 12, 2014
report viewer in 2013 express
'Unexpected Token ILLEGAL' Error
I had this once because word sometimes adds the bizarre double quotes
Thursday, May 8, 2014
Some Hashing functions
public static string
SHA1Hash(string to_be_hash)
{
SHA1CryptoServiceProvider
sha1 = new SHA1CryptoServiceProvider();
byte[]
hash = sha1.ComputeHash(GetBytes(to_be_hash));
string
delimitedHexHash = BitConverter.ToString(hash);
string
hexHash = delimitedHexHash.Replace("-",
"");
return
hexHash;
}
public static string
HMACRIPEMD160Hash(string to_be_hash)
{
Guid
g = new Guid("AD56BC66-3C2F-4B69-B9C9-1E0305D95E99");
byte[]
temp = null;
using
(HMACRIPEMD160 hmac = new HMACRIPEMD160(g.ToByteArray()))
{
temp =
hmac.ComputeHash(GetBytes(to_be_hash));
}
//return
Convert.ToBase64String(temp);
return
ByteArrayToString(temp);
}
Readonly on reference types
public class testReadonly
{
public readonly List<string>
l = new List<string>();
}
testReadonly tr
= new testReadonly();
tr.l.Add("fdgdgf");
this is ok because of this
Wednesday, May 7, 2014
The type or namespace name 'Blah' does not exist in the namespace 'heh.heh' (are you missing an assembly reference?)
I was getting this in a team city build because the dll was directly referenced instead of the project being referenced.
This has great consequences with release builds
As I understand it,only with a project reference is the bin created
This has great consequences with release builds
As I understand it,only with a project reference is the bin created
OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name
this happened with an unhandled error that didn't have wcf fault shielding
Friday, May 2, 2014
REST Clients
I had a situation where I needed to pass security in a HTTP header - Postman worked while SOAPUI didn't
Labels:
http headers,
postman,
REST Services,
soap ui
Compound Tertiary Operators
if you don't surround with parenthesis - you can have some funky errors
Wednesday, April 30, 2014
Orchard Site is just showing directory listing
the mdf is read only
Tuesday, April 29, 2014
assembly generation failed strong name
all referenced dll's need to be signed if the calling assembly is signed
Friday, April 25, 2014
How to create routes in Orchard
adding a new page will do it automatically but it's recommended to use a route.cs file
Thursday, April 24, 2014
server unexpectedly closed connection - winscp
may be caused by too many users connected to server
Friday, April 11, 2014
rest service working on local but not on server
may just need a bindingConfiguration that handles https
<security mode="Transport">
<security mode="Transport">
WebHost failed to process a request- specifies multiple request body parameters to be serialized without any wrapper elements.
instead of changing the code i changed the behavior from webHttp to enableWebScript
Wednesday, April 9, 2014
Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.
change behaviours
400 Bad Request
will happen when you call a REST service using the wrong address (the address behavior that is not rest)
Internet Explorer cannot display the webpage
Memory gates checking failed because the free memory (nnnnnnnn bytes) is less than 5% of total memory.
restart IIS
Monday, April 7, 2014
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
means someone has a lock on one of the files
Wednesday, April 2, 2014
To enable net.pipes
add http,net.pipe to advanced settings->enabled protocols
Monday, March 31, 2014
to clear WCF dll's
recycle the app pool 0- stopping the service is not enough
Thursday, March 27, 2014
Execute rights to user defined table type
GRANT EXEC ON TYPE::[BLAH_schema].[blah_tabletype] TO BLAH_USER
Friday, March 21, 2014
The ChannelDispatcher at 'net.pipe://blah' with contract(s) '"IBlah"' is unable to open its IChannelListener
sometimes just restart netpipe listener adapter
Thursday, March 20, 2014
Wednesday, March 19, 2014
Friday, March 7, 2014
If you can't find the error in the team city log
go to the log team city creates under c:\temp in the destination server for more detailed info
Thursday, March 6, 2014
Tuesday, March 4, 2014
metadata could not be found
could be a red herring - fix the other errors first
Debugging Resource strings are unavailable
is normal silverlight behavior
Monday, February 24, 2014
The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name.
Variables are only allowed when ordering by an expression referencing a column name.
this means using the variable in a case or if statement (me thinks)
this means using the variable in a case or if statement (me thinks)
Wednesday, February 12, 2014
Remove json syntax from strings
with JavaScriptSerializer class
JavaScriptSerializer javaScriptDeserializer = new JavaScriptSerializer();
List<string> idList = javaScriptDeserializer.Deserialize<List<String>>(Ids);
JavaScriptSerializer javaScriptDeserializer = new JavaScriptSerializer();
List<string> idList = javaScriptDeserializer.Deserialize<List<String>>(Ids);
Social skills over Methodology
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
Subscribe to:
Posts (Atom)