Skip to content

Instantly share code, notes, and snippets.

View scottrippey's full-sized avatar

Scott Rippey scottrippey

View GitHub Profile
@scottrippey
scottrippey / CustomComparer.cs
Created October 6, 2011 17:33
CustomComparer, used for comparing objects based on custom criteria or a custom lambda
public class CustomComparer<TSource, TCompareType> : IEqualityComparer<TSource> where TSource : class
{
private readonly Func<TSource, TCompareType> getComparisonObject;
public CustomComparer(Func<TSource,TCompareType> getComparisonObject)
{
if (getComparisonObject == null) throw new ArgumentNullException("getComparisonObject");
this.getComparisonObject = getComparisonObject;
}
/// <summary>
@scottrippey
scottrippey / Example.js
Created November 8, 2011 20:32
JavaScript that uses a Regex to split a string, ensuring balanced parenthesis and balanced quotes.
var input = "a, b, (c, d), (e, (f, g), h), 'i, j, (k, l), m', 'n, \"o, 'p', q\", r'";
var result = SplitBalanced(input, ",");
// Results:
["a",
" b",
" (c, d)",
" (e, (f, g), h)",
" 'i, j, (k, l), m'",
" 'n \"o, 'p', q\", r'"];
@scottrippey
scottrippey / jQuery.antiforgerytoken.js
Created August 22, 2012 18:21
ASP.NET MVC AntiForgeryToken + AJAX = jQuery to the rescue
// Setup CSRF safety for AJAX:
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
if (options.type.toUpperCase() === "POST") {
// We need to add the verificationToken to all POSTs
var token = $("input[name^=__RequestVerificationToken]").first();
if (!token.length) return;
var tokenName = token.attr("name");
@scottrippey
scottrippey / FixedHeader.js
Created August 24, 2012 17:43
Code Review of FixedHeader.js
Uverse.widgets.FixedHeader = new Class({
Implements: [ Options ]
, el: null
, sectionsNavigationSelector: '.sections-navigation'
, _fixedZIndex: 15
, _sectionsNavigation: null
, _regularBodyPaddingTop: null
, _regularMastheadMarginTop: null
, _onScrollHandler: function() {
var bodyPaddingTop;
@scottrippey
scottrippey / Readme.md
Created January 30, 2014 21:51
Comparing initConfig versus mergeConfig

For this example, we're building several packages: core-js, core-css, extras-js, and extras-css.

Using grunt.initConfig, you'll see that our packages are completely intermingled. In order, you'll see core-css, core-js, extras-js, extras-css, options, core-js, extras-js, options, core-css, core-js, extras-css, and extras-js.

Using grunt.mergeConfig, the resulting config object is identical. However, each package comprises its own code block, and are completely modular from other packages. In order, you'll see options, core-js, core-css, extras-js, and extras-css.

Any project that builds more than 1 simple package will greatly benefit from this organizational pattern.
For example, Bootstrap's Gruntfile builds 4 separate packages (bootstrap.js, bootstrap.css, bootstrap-theme.css, docs), jQuery UI builds 3 packages (jquery-ui.js, jquery-ui-i18n.js, jquery-ui.css), and practically every significant project builds multiple packages.

@scottrippey
scottrippey / jasmine-these usage example.js
Last active August 29, 2015 14:16
Jasmine test cases - "these"
describe("typeof", function() {
these("expects ", {
"0 to output number": [ 0, "number" ],
"NaN to output number": [ NaN, "number" ],
"undefined to output undefined": [ undefined, "undefined" ],
"null to output object": [ null, "object" ],
"Date to output object": [ new Date(), "object" ],
"{} to output object": [ {}, "object" ],
"anon function to output object": [ function(){}, "object" ],
}, function(input, expectedOutput) {
@scottrippey
scottrippey / jasmine-these-2 usage examples.js
Last active August 29, 2015 14:16
Jasmine test cases - "these" - version 2 (supporting message templates)
describe("typeof", function() {
// You can pass in an object of test cases:
these("should output {1} when the input is ", {
"any number": [ 0, "number" ],
"NaN": [ NaN, "number" ],
"undefined": [ undefined, "undefined" ],
"null": [ null, "object" ],
"a Date": [ new Date(), "object" ],
"anon object": [ {}, "object" ],
"anon function": [ function(){}, "object" ],
@scottrippey
scottrippey / commands\pages\profile.js
Last active November 9, 2015 19:51
addElementCommands ideas
browser.addElementCommands({
// There are multiple ways to define an element.
// Just a selector:
"profile_Table_": "#table",
// The selector is a function:
"profile_Table_": function getSelector(rowAndColumn){
return "//a[" + rowAndColumn.row + "] span[" + rowAndColumn.column + "]";
},
"profile_Table_": function(rowAndColumn) {
@scottrippey
scottrippey / page objects syntax.js
Last active November 25, 2015 17:38
Here are theoretical examples of how "page objects" would work. Looking for an expressive syntax that maximizes the test-writing experience.
describe("page objects", function() {
var loginPage = pageObjects.loginPage;
it("here's what we've got now; page commands and element commands", function() {
return browser
.loginPage_email_setValue("a@b.c")
.loginPage_password_setValue("pass")
.loginPage_loginButton_click()
.loginPage_errorMessage_getText().should.become("Oops, some error")
;
@scottrippey
scottrippey / template-helpers example.js
Last active February 13, 2019 10:49
ES6 Template Helpers
import { unindent, repeat, truthy } from "template-helpers";
function createMessage(user, notifications) {
return unindent(truthy`
Hello, ${ user.name }!
${(notifications.length > 0) && truthy`
You have ${ notifications.length } new notification${ (notifications.length > 1) && "s" }.
${repeat(notifications, notification => truthy`
* ${ notification.title } ${ notification.important && "!" }
`)}