Skip to content

Instantly share code, notes, and snippets.

@cmarkle27
cmarkle27 / app.js
Created August 12, 2011 20:51
CMTest
function renderNewPostForm(request, response){
response.writeHead(200, {'Content-type': 'text/html'});
response.end('hello world');
}
@cmarkle27
cmarkle27 / gist:3252823
Created August 3, 2012 23:57
Log handlers for all jQuery events
jQuery.each($(document).data('events'), function(i, event){
jQuery.each(event, function(i, handler){
console.log(handler.toString());
});
});
@cmarkle27
cmarkle27 / index.html
Created August 4, 2012 00:30
html page
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>HTML</title>
</head>
<body>
<div>content</div>
</body>
</html>
@cmarkle27
cmarkle27 / ajax.js
Created August 4, 2012 01:10
Basic Ajax Request
function ajaxRequest(target, method, params, callback, graph) {
var xmlhttp=false;
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
@cmarkle27
cmarkle27 / jQuery-Ajax.js
Created August 4, 2012 01:20
jQuery Ajax using defereds
var request = $.ajax({
url: "/url",
type: "POST",
data: {"id" : 0},
dataType: "html"
});
request.done(function(msg) {
console.log(msg);
});
@cmarkle27
cmarkle27 / inArray.js
Created August 4, 2012 01:26
inArray (Javascript)
function inArray(item, arr) {
for (var p=0; p<arr.length; p++) if (item === arr[p]) return true;
return false;
}
// 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;');
@cmarkle27
cmarkle27 / jquery.advanced-plugin.js
Created August 4, 2012 18:48
Advanced jQuery Plugin
// plug it in, plug it in
(function($) {
var paraCount = function() {
return {
options: {
itemClass: 'awesome',
baseUrl: "/",
@cmarkle27
cmarkle27 / jquery.simple-plugin.js
Created August 4, 2012 19:10
Simple jQuery Plugin
(function($) {
// functions and vars here
var underline = function underline(e) {
$(e.currentTarget).css({ "color" : "yellow" });
};
// --------------------------------------------------------------------
$.fn.simpleOne = function() {
@cmarkle27
cmarkle27 / jQuery-when-ajax.js
Created August 4, 2012 22:23
jQuery Ajax using when
function doAjax(){
return $.get('/echo/html/');
}
function doMoreAjax(){
return $.get('/echo/html/');
}
$.when( doAjax(), doMoreAjax() )
.then(function(){