Skip to content

Instantly share code, notes, and snippets.

View bgrins's full-sized avatar

Brian Grinstead bgrins

View GitHub Profile
/*
jQuery outerHTML plugin with ownerDocument fix
See: http://www.briangrinstead.com/blog/jquery-outerhtml-snippet
Based off of: http://brandonaaron.net/blog/2007/06/17/jquery-snippets-outerhtml/
*/
$.fn.outerHTML = function() {
var doc = this[0] ? this[0].ownerDocument : document;
return $('<div>', doc).append(this.eq(0).clone()).html();
};
/*
http://lanitdev.wordpress.com/2009/06/08/extending-jquery-to-select-asp-controls/
Enables $(":asp(id)") selector in jQuery for dealing with ASP Server IDs in JavaScript
Example: $(":asp(txtPhoneNumber)")
*/
jQuery.expr[':'].asp = function(elem, i, match) {
return (elem.id && elem.id.match(match[3] + "$"));
};
<script type='text/javascript' src='astar.js'></script>
<script type='text/javascript'>
var graph = new Graph([
[1,1,1,1],
[0,1,1,0],
[0,0,1,1]
]);
var start = graph.grid[0][0];
var end = graph.grid[1][2];
var result = astar.search(graph, start, end);
/*
An implementation of: http://javascriptweblog.wordpress.com/2010/11/29/json-and-jsonp/
that handles multiple connections at once (don't want to replace the global callback if second
request is sent after the first, but returns before.
*/
(function(global) {
var callbackCounter = 0;
var evalJSONP = function(callback) {
<html>
<head>
<style>
html,body {height:100%;margin:0;padding:0;}
#app {
height:100%;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-align:stretch;
@bgrins
bgrins / gist:1789787
Created February 10, 2012 13:58
C# Multipart File Upload
// Implements multipart/form-data POST in C# http://www.ietf.org/rfc/rfc2388.txt
// http://www.briangrinstead.com/blog/multipart-form-post-in-c
public static class FormUpload
{
private static readonly Encoding encoding = Encoding.UTF8;
public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters)
{
string formDataBoundary = String.Format("----------{0:N}", Guid.NewGuid());
string contentType = "multipart/form-data; boundary=" + formDataBoundary;
@bgrins
bgrins / gist:2713746
Created May 16, 2012 20:37
CoMORichWeb Slides
https://docs.google.com/presentation/d/1Eyns40c5J6n2ep7NUMid7ipSuR-jATF1pdWQNuuwp-4/edit
@bgrins
bgrins / gist:4141504
Last active October 13, 2015 04:47
JS function to copy notes from essays into the title attributes of their links. Can run this straight from the console or add it as a devtools snippet.
// For instance: http://paulgraham.com/growth.html
// Copy the following into devtools console, then you should see note contents when hovering the link
[].forEach.call(document.querySelectorAll("a[href*='#f']"), function(l) {
var to = document.querySelector('[name=' + l.href.split('#')[1] + ']');
var text = '';
while ((to = to.nextSibling) && to.tagName !== "A") {
text+= to.textContent.replace(/\n/g, ' ') + '\n';
}
text = text.replace(/^\s*\]\s*/, '').replace(/\s*\[\s*/, '').replace(/\n{2,}/g, '\n\n');
@bgrins
bgrins / gist:4148366
Created November 26, 2012 14:04
Create a sizzle expression in jQuery 1.8 and older
// Create a sizzle expression using jQuery 1.8 style and older style.
// This one returns elements which have an ID that ends with a string passed in.
// <div id="prefix_test"></div>
// $(":asp(test)")
if ($.expr.createPseudo) {
jQuery.expr[':'].asp = $.expr.createPseudo(function( id ) {
return function(elem) {
return elem.id && elem.id.match(id + "$")
@bgrins
bgrins / setowner.bat
Created January 2, 2013 21:04
Sometimes Windows permissions get messed up such that even an admin cannot access the file. The process for fixing this through the UI is very slow going, so here is a script to set the owner to Administrator then give the Administrator full permissions to said files.
:: Fix ownership on a directory
:: Download subinacl (if needed) at http://www.microsoft.com/en-us/download/details.aspx?id=23510
C:\subinacl /file *.* /setowner=COMPUTER\Administrator
cacls *.* /G Administrator:F