Skip to content

Instantly share code, notes, and snippets.

View bgrins's full-sized avatar

Brian Grinstead bgrins

View GitHub Profile
@bgrins
bgrins / gist:4625572
Created January 24, 2013 17:40
Adds ability to pass default parameter for query string values in C# web projects.
/*
Adds ability to pass default parameter for query string values in C# web projects.
http://example.com/?key=1
GET("key", "default") returns "1"
http://example.com/
GET("key", "default") returns "default"
*/
@bgrins
bgrins / ui-iframe-mouseup.js
Last active January 11, 2017 08:56
Iframe mouseup check. If mouseup happened on outer document, fire it on this one
_mouseMove: function(event) {
// IE mouseup check - mouseup happened when mouse was out of window
if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
return this._mouseUp(event);
}
// Iframe mouseup check. If mouseup happened on outer document, fire it on this one
else if (!event.which) {
return this._mouseUp(event);
}
@bgrins
bgrins / Log-.md
Last active August 1, 2023 16:32
Prevent errors on console methods when no console present and expose a global 'log' function.

Javascript log Function

Every time I start a new project, I want to pull in a log function that allows the same functionality as the console.log, including the full functionality of the Console API.

There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.

This is an attempt to once and for all document the function that I pull in to new projects. There are two different options:

  • The full version: Inspired by the plugin in HTML5 Boilerplate. Use this if you are writing an application and want to create a window.log function. Additionally,
@bgrins
bgrins / new-branch-from-upstream
Created April 12, 2013 16:42
Used this to clean up a branch in preparation for a pull request
git diff master > ~/Desktop/patch.patch
git checkout -b for-upstream remotes/upstream/master
patch -p1 < ~/Desktop/patch.patch
@bgrins
bgrins / backbone-helper.js
Created April 26, 2013 16:16
backbone-helpers: extend Backbone natives with some convenience methods.
// backbone-helpers: extend Backbone natives with some convenience methods
// Implemented by overriding the extend function to modify the options passed into the original extend
// Adds the following methods:
// Model.isDirty() -> check if a model has changed since the last sync with the server
// Collection.getChangedSinceLastSave() -> return all the models that return true on isDirty()
// Collection.saveAllChanged() -> save all the models returned by getChangedSinceLastSave()
(function (extend) {
@bgrins
bgrins / state.js
Created May 1, 2013 15:00
Wrap pushState and popState into a helper function that feature detects and fires callbacks http://jsbin.com/olabac/3/edit
var State = (function() {
var supported = !!window.history;
var enabled = true;
var popCallbacks = [];
var pushCallbacks = [];
var initialURL = location.href;
@bgrins
bgrins / OnActionExecuting.cs
Created May 2, 2013 13:13
Prevent all non GET/POST requests in a base controller class in asp mvc
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
string httpMethod = filterContext.RequestContext.HttpContext.Request.HttpMethod.ToUpper();
// Prevent all non GET/POST requests
if (httpMethod != "GET" && httpMethod != "POST")
{
filterContext.Result = new HttpStatusCodeResult(404);
return;
@bgrins
bgrins / export-chrome-bookmarks.js
Last active February 26, 2024 04:00
Reminder of how to export bookmarks from Chrome as text.
/*
Export bookmarks from Chrome as text.
Go to Bookmarks Manager->Organize->Export to HTML file.
Then open that file, open console and run this command:
*/
[].map.call(document.querySelectorAll("dt a"), function(a) {
return a.textContent + " - " + a.href
}).join("\n");
@bgrins
bgrins / .zshrc
Created June 19, 2013 01:34 — forked from SlexAxton/.zshrc
gifify() {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
rm out-static*.png
else
ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
fi
else