Skip to content

Instantly share code, notes, and snippets.

@seamusjr
seamusjr / replaceHtml.js
Created January 6, 2011 17:33
From http://blog.stevenlevithan.com/archives/faster-than-innerhtml using innerHTML and dom methods to replace elements
function replaceHtml(el, html) {
var oldEl = typeof el === "string" ? document.getElementById(el) : el;
/* @cc_on // Pure innerHTML is slightly faster in IE
oldEl.innerHTML = html;
return oldEl;
@*/
var newEl = oldEl.cloneNode(false);
newEl.innerHTML = html;
oldEl.parentNode.replaceChild(newEl, oldEl);
// Since we just removed the old element from the DOM, return a reference
@seamusjr
seamusjr / getGoogleMapsLatLng
Created April 2, 2011 20:25
return latLng on click
google.maps.event.addListener(map, 'click', function(event) {
console.log(event.latLng);
});
@seamusjr
seamusjr / insertCoords
Created April 3, 2011 16:32
get latLng has string of coords from google.maps latLng insert into node
function getCoords() {
var latlng_str = marker.getPosition().toString();
document.getElementById("coords").textContent = latlng_str;
};
@seamusjr
seamusjr / SpecRunner.html
Created June 24, 2011 17:00
Jasmine/JQuery/jasmine-jquery test runner html template
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.0.2/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.0.2/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.2/jasmine-html.js"></script>
<script src="lib/jquery-1.6.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/jasmine-jquery-1.2.0.js" type="text/javascript" charset="utf-8"></script>
@seamusjr
seamusjr / JS Util solution using underscore.js
Created July 7, 2011 19:54 — forked from HenrikJoreteg/JS Util solution using underscore.js
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&amp;')
.replace(/>/g,'&gt;')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
@seamusjr
seamusjr / backbone_template.html
Created July 8, 2011 03:31
Backbone HTML template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<!-- CSS -->
<style type="text/css">
@seamusjr
seamusjr / class.js
Created July 29, 2011 16:21
Simple JS Inheritance, John Resig example
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
@seamusjr
seamusjr / paperclip_loop.rb
Created August 14, 2011 21:47
loop collection images paperclip
<% for asset in @post.assets %>
<li><%= link_to image_tag(asset.asset.url(:thumb)), asset.asset.url(:original) %></li>
<% end %>
$(document).keydown(function(e) {
if(typeof e != 'undefined'){
if(e.altKey && e.keyCode == 115){
e.keyCode = 0;
alert("Alt + F4");
return false;
}
}
});
@seamusjr
seamusjr / native_js.html
Created October 25, 2011 22:11
native js event handler example
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<!-- Date: 2011-10-25 -->
</head>
<body>
<button id="load-application">Load Application</button>