Skip to content

Instantly share code, notes, and snippets.

View brainded's full-sized avatar

Adam Valverde brainded

View GitHub Profile
@brainded
brainded / Validate.cs
Last active December 15, 2015 01:39
Run Validator Manually on DataAnnotations. Useful when using DataAnnotations in a Non MVC Context, like a console application or a service.
var objectToValidate = new ObjectToValidate();
var context = new ValidationContext(goUpgradesStandbyProductRequestData, null, null);
var results = new List<ValidationResult>();
bool isValid = Validator.TryValidateObject(objectToValidate, context, results, true);
@brainded
brainded / JS Patterns.js
Last active January 2, 2016 04:19
Because I always forget some of the basic JS patterns I have used over the last 2 years
// create 'bobsburgers' if it is not already declared
var bobsburgers = bobsburgers || {};
// create a new namespace under 'bobsburgers'
bobsburgers.buyburgers = (function (locallyScopedVariable) { //globallyScopedVariable got aliased to locallyScopedVariable
//define a function that is locally scoped
var _localFunction = function (params) {
//do something interesting
};
@brainded
brainded / RenderViewToString.cs
Last active January 4, 2016 03:49
Useful snippet that allows you to render a MVC View to a string.
private string RenderViewToString(string viewName, object model)
{
// assign the model of the controller from which this method was called to the instance of the passed controller (a new instance, by the way)
this.ViewData.Model = model;
// initialize a string builder
using (StringWriter sw = new StringWriter())
{
// find and load the view or partial view, pass it through the controller factory
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(this.ControllerContext, viewName);
@brainded
brainded / MakeCert.txt
Last active November 2, 2016 11:42
Create a locally signed Cert for a domain name.
Step 1
Open 'Developer Command Prompt for VS2012' and run the following:
makecert -r -pe -n "CN=*.bobsburgers.local" -b 01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
//We are using *.bobsburgers.local because this will allow us to use the single cert for all websites on the domain, like burgers.bobsburgers.local and fries.bobsburgers.local
Step 2
Open IIS, expand Sites, right click first site, Edit Bindings, Add HTTPS binding, select *.bobsburgers.local cert, click ok
@brainded
brainded / CustomValidationStyle.css
Created January 22, 2014 18:30
Some custom validation stuff done in jQuery Mobile to enable control highlighting when validation fails. Without this jQMobile puts the css around the actual control instead of it's own wrapper that adds style to the control. The net effect is the border is applied to the rounded controls.
.input-validation-error {
border: 2px solid #a40025 !important;
}
@brainded
brainded / Checkbox.css
Last active January 4, 2016 03:49
Custom checkbox that works with all browsers, web testing frameworks as well as accessibility tools like Chrome Vox.
.custom-checkbox input[type="checkbox"] {
display: inline-block;
width: 20px;
height: 20px;
/*hide the actual checkbox, but dont do a display none because that breaks a ton of stuff like testing frameworks*/
opacity: 0.01;
filter: alpha(opacity=0.01);
cursor: pointer;
}
@brainded
brainded / WindowExtensions.cs
Created January 23, 2014 20:30
Neat little extension file for C# that allows a standard Window to flash when something is done. See http://www.jarloo.com/ for more C# stuff like this.
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace Jarloo
{
public static class WindowExtensions
{
#region Window Flashing API Stuff
@brainded
brainded / WcfException.config
Created January 24, 2014 21:02
Wcf Exception configuration to enable logging to file when troubleshooting Wcf issues.
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:logclient.svclog" />
@brainded
brainded / JsonExtensions.cs
Last active September 16, 2018 17:18
Code snippet to make a ToJson extension method for objects in C#. Relies on NewtonSoft.Json Nuget.
public static class ObjectExtensions
{
/// <summary>
/// The string representation of null.
/// </summary>
private static readonly string Null = "null";
/// <summary>
/// The string representation of exception.
/// </summary>
@brainded
brainded / Rights.sql
Created February 20, 2014 22:00
Get a list of Stored Procedures a user has rights to in TSQL.
use Database
go
execute as user = 'Some_User'
go
select has_perms_by_name('p', 'OBJECT', 'execute') as HasRights, name from sys.procedures
go
revert --This will discontinue the above EXECUTE AS to stop you from impersonating Some_User