Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
dieseltravis / bench.js
Created August 20, 2009 15:46
Benchmarking JS with and without Firebug's console
(function (w) {
var console = w.console,
BenchLog = "",
Bench = {},
BenchLogWrite = function (message) {
if (console && console.log) {
console.log(message);
} else { // no console logger
@dieseltravis
dieseltravis / gist:248358
Created December 3, 2009 17:34
re-ordering items with linq
private void ReorderItem(Guid itemToMoveID, int newOrder)
{
var db = new SomeDataContext();
var selectedItems = (from b in db.SomeItems
where b.CategoryId == Category.SelectedCategoryID
orderby b.OrderBy ascending
select b).ToList();
SomeItem itemToMove = selectedItems.Find(b => b.ID == itemToMoveID);
@dieseltravis
dieseltravis / gist:286147
Created January 25, 2010 19:30
use jquery to help trim SPAN tags without attributes
// empty SPAN trimming code:
var emptySpanTags = /<span(?:\b[^>]*)?><\/span>/gi;
var noAttributeFilter = function () {
// make sure the element has no elements
if (this && this.attributes) {
return (this.attributes.length <= 0);
}
return true;
};
var trimPlainSpans = function (html) {
@dieseltravis
dieseltravis / gist:290085
Created January 29, 2010 20:21
delete .svn and _svn stuff
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *_svn*') DO RMDIR /S /Q "%%G"
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
@dieseltravis
dieseltravis / gist:295062
Created February 4, 2010 20:27
using List(Of T).Find(Predicate) in VB.Net 2.0
' VB.Net 2.0
' a class for videos is what I was using my original code for
Public Class Video
Private _id As Integer
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
@dieseltravis
dieseltravis / gist:313865
Created February 24, 2010 21:28
Bookmarklet to easily enumerate a global javascript object
// enumerate an object, ex: "window"
(function(){
var enumObj = function(obj) {
var props = "";
for (var o in obj) {
props += o;
props += ": \t";
props += obj[o];
props += "\n";
}
function EntityToNumeric(entity) {
var obj = document.createElement("div");
obj.innerHTML = entity;
return "&#" + (obj.textContent || obj.firstChild.nodeValue).charCodeAt(0) + ";";
}
// usage:
var html = "&amp;&nbsp;&copy;&reg;&lt;&gt;";
html = html.replace(/&\w+;/gi, EntityToNumeric);
alert(html); // "&#38;&#160;&#169;&#174;&#60;&#62;"
// bookmarklet to introspect the source of current page
javascript:(function(d,h){h=d.documentElement.innerHTML;d.open();d.write('<pre>'+('<!DOCTYPE html><html>'+h+'</html>').replace(/[<>]/g,function(m){return{'<':'&lt;','>':'&gt;'}[m]})+'</pre>')})(document);
/*
* jQuery fasterTrim Plugin
* version: 1.0.1
* @requires jQuery v1.0.x or later
*
* licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* @version $Id: jquery.fastertrim.js 2 2010-03-04 12:00:00Z $
* @author Travis Hardiman https://forum.jquery.com/user/travis.hardiman http://travis.servebeer.com
@dieseltravis
dieseltravis / jquery.fastertrim.js
Created March 4, 2010 22:44 — forked from dcneiner/jquery.fastertrim.js
Doug saves the day with a more streamlined plugin and feature suggestions
/*
* jQuery fasterTrim Plugin
* version: 1.0.5
* @requires jQuery v1.0.x or later
*
* dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/gpl-2.0.php
*
* @version $Id: jquery.fastertrim.js 5 2010-03-12 12:00:00Z $