Objective C defining UIColor constants

A UIColor is not mutable. I usually do this with colors, fonts and images. You could easily modify it to use singletons or have a static initializer. @interface UIColor (MyProject) +(UIColor *) colorForSomePurpose; @end @implementation UIColor (MyProject) +(UIColor *) colorForSomePurpose { return [UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]; } @end

Writing a Log file in C/C++

The standard method of logging (in my experience) is to use either the stdout or stderr streams. In C++ to use these you would need to include iostream, and use as below: #include <iostream> int main(int argc, char* argv[]) { using std::cout; using std::cerr; using std::endl; cout << “Output message” << endl; cerr << “Error … Read more

Create DataTemplate in codebehind

Although Archedius’s method works, officially it is deprecated and instead recommended way to programmatically create a template is to load XAML from a string or a memory stream using the Load method of the XamlReader class like this… public DataTemplate Create(Type type) { StringReader stringReader = new StringReader( @”<DataTemplate xmlns=””http://schemas.microsoft.com/winfx/2006/xaml/presentation””> <” + type.Name + @” … Read more

How can I show a viewbag as html?

Everyone is correct in the use of @Html.Raw() but I want to point out to be careful with this, as it can make your site susceptible to XSS vulnerabilities. I would combine the @Html.Raw(ViewBag.SomeMessage) with Microsoft’s Anti-XSS Library to make sure you do not introduce any vulnerabilities from this. Edit: The advantage of the Anti-XSS … Read more