Skip to content

Instantly share code, notes, and snippets.

View jessegavin's full-sized avatar

Jesse Gavin jessegavin

View GitHub Profile
@jessegavin
jessegavin / lodash-mixins.js
Created September 4, 2013 21:33
Here's a lodash mixin that works sort of like _.filter(), however the matching items will be removed from the source array.
_.mixin({
'multiSplice': function (array, indexes) {
if (!_.isArray(array) || !_.isArray(indexes) || !_.all(indexes, _.isNumber)) {
return [];
}
var results = [];
if (indexes.length > 0) {
var i = indexes.length - 1;
for (; i >= 0; i--) {
Outcome<string> IAuthenticationService.ValidatePassword(IDssPrincipal dssPrincipal, string password)
{
const int minimumLength = 8;
const int maximumLength = 20;
const string specialCharactersPattern = @"\#\$\%\&\@\*\+\-\=\!\.\?\:\;\(\)\[\]\{\}\^\~_";
var observations = new List<string>();
var email = dssPrincipal.Identity.EmailAddress.ToMaybe();
// Password must not be null
@jessegavin
jessegavin / gist:3033734
Created July 2, 2012 15:17
Functional Question
private IEnumerable<Func<string, Maybe<string>, Outcome<string>>> GetValidators()
{
// Password cannot be empty
yield return (password, email) => string.IsNullOrWhiteSpace(password)
? Outcome.Failure("Password cannot be empty")
: Outcome.Success();
// Password must have at least 8 characters
yield return (password, email) =>
{
Server Error in '/' Application.
The property MvcApp.Models.ISpy.Name could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The property MvcApp.Models.ISpy.Name could not be found.
Source Error:
@jessegavin
jessegavin / gist:1153155
Created August 18, 2011 02:31
Code example for StackOverflow question #7087312
// ----------------------------------------------------------------
// This example shows my solution for the question I posted here:
// http://stackoverflow.com/questions/7087312
// ----------------------------------------------------------------
public class Person {
public string First { get; set; }
public string Last { get; set; }
public string Twitter { get; set; }
}
private void SendHttpRequest(string httpMethod, string mimeType, string requestBody, string uri)
{
byte[] xmlBytes = Encoding.UTF8.GetBytes(requestBody);
var md5Base64 = Hasher.Md5Hash(xmlBytes).ToBase64();
var dateString = GetDateString();
var stringToSign = GetStringToSign(httpMethod, md5Base64, mimeType, uri, dateString, null);
var signature = Hasher.GetSignature(SecretKey, stringToSign);
Console.Write(DebugMessage("String To Sign", stringToSign));
POST http://preprod-services.stupeflix.com/stupeflix-1.0/screenfeed/c30e406f/?Date=1306188442&AccessKey=ZvlQcWYSJ13iJFjbPo82&Signature=aa327acf9a0d0defad49d0be23debe476a0f3b0f HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-MD5: PtwIhXcJHapJ1NoJRN+pRw==
Host: preprod-services.stupeflix.com
Content-Length: 226
Expect: 100-continue
ProfilesXML=%3cprofiles%3e%3cprofile+name%3d%22ntsc-wide-wmv%22%3e%3cs3+bucket%3d%22screenfeed%22+resourcePrefix%3d%22c30e406f%22%3e%3cmeta%3e%3cacl%3epublic%3c%2facl%3e%3c%2fmeta%3e%3c%2fs3%3e%3c%2fprofile%3e%3c%2fprofiles%3e
@jessegavin
jessegavin / SO #5462820
Created March 28, 2011 18:38
Answer to StackOverflow Question #5462820
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geoResults = {};
@jessegavin
jessegavin / gist:847637
Created February 28, 2011 17:08
Spacecrafting slideshow usage
var ss = $("#slideshow-display").slideshow({
urls: ['image.jpg', 'image2.jpg'], // This is the only required setting
photoBaseUrl: "http://photos.screenfeed.com/',
interval: 3000, // Number of milliseconds each photo should be shown
transitionDuration: 300, // Time it takes for fade animation to complete
preloadBuffer: 3, // Number of images to preload before slideshow starts
onImageChanging: null, // If specified, this is fired right before the image is swapped
onImageLoading: null, // If specified, this is fired when an image is requested.