Skip to content

Instantly share code, notes, and snippets.

@Kotrotsos
Kotrotsos / gist:976222
Created May 17, 2011 09:54
Sexy element declaration
<style>
.highlight { background-color:yellow; }
</style>
<script>
$("<div />", {
text: "click here",
click: function()
{
$(this).toggleClass("highlight");
}
@Kotrotsos
Kotrotsos / Typeahead.js
Created July 9, 2012 06:49
Type ahead in Bootstrap
$('.typeahead').typeahead({
source: function (typeahead, query) {
return $.post('/typeahead', { query: query }, function (data) {
return typeahead.process(data);
});
}
});
@Kotrotsos
Kotrotsos / gist:3075791
Created July 9, 2012 10:54
Override underscore template embed tags to a more sane {{ }}
function template(str) {
var orig_settings = _.templateSettings;
_.templateSettings = {
interpolate : /\{\{([\s\S]+?)\}\}/g
};
var t = _.template(str);
_.templateSettings = orig_settings;
@Kotrotsos
Kotrotsos / gist:3096825
Created July 12, 2012 08:53
Quick Javascript testing function.
function assert( err,checkThis ) { if( !checkThis ) { throw err; } }
// To use (Check js console):
assert( 'This will return -nothing.', function() {
return true;
});
assert('Well, this is an error', false);
@Kotrotsos
Kotrotsos / measure.html
Created September 13, 2012 12:16
measure onReady in Google Analytics
<html>
<head>
<script> ___start___ = new Date; </script>
<script>
$(function() {
var performance = new Date - ___start___;
_gaq.push(
'_trackEvent',
@Kotrotsos
Kotrotsos / map.js
Created November 1, 2012 06:35
map
function map(func, array) {
var result = [];
forEach(array, function (element) {
result.push(func(element));
});
return result;
}
show(map(Math.round, [0.01, 2, 9.89, Math.PI]));
@Kotrotsos
Kotrotsos / unless.js
Created November 3, 2012 15:20
unless
// Extend the function prototype with the method 'unless' (which is naughty...)
Function.prototype.unless = function(assert) {
if (!assert) {
this.call();
}
}
var doThisTestFunction = function() {
console.log('heeeeeeyooooo')
}
@Kotrotsos
Kotrotsos / gist:4013879
Created November 4, 2012 21:34
Brackets vs . notation
var a = { b: 'c' },
r,
brackets,
dot,
run = 1000,
frames = 1000000;
console.log("Dot notation, iterations total: ", run * frames)
console.time( 'dot notation' );
@Kotrotsos
Kotrotsos / Custom.css
Created November 8, 2012 07:15
Custom Chrome inspector CSS
/**********************************************/
/*
/* Darker Skin by Darcy Clarke - 2011
/*
/* For how to install, or more themes, check out:
/* http://darcyclarke.me/design/skin-your-chrome-inspector/
/*
/* Color scheme is based on Joe Bergantine's Specials Board:
/* http://joebergantine.com/werkstatt/seestyle
/*
@Kotrotsos
Kotrotsos / fetch.js
Created November 14, 2012 09:36
Script loader to use with Chrome snippets
function fetch(url,success){
var script=document.createElement('script');
script.src=url;
var head=document.getElementsByTagName('head')[0],
done=false;
// Attach handlers for all browsers
script.onload=script.onreadystatechange = function(){
if ( !done && (!this.readyState
|| this.readyState == 'loaded'
|| this.readyState == 'complete') ) {