Skip to content

Instantly share code, notes, and snippets.

View easierbycode's full-sized avatar

▓▒░ ♔ Daniel ♔ ░▒▓ easierbycode

View GitHub Profile
@easierbycode
easierbycode / chat.html
Created October 27, 2011 17:44 — forked from JoeyButler/chat.html
Simple Chat app
<!DOCTYPE html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'></script>
<script>
$(document).ready(function(){
function debug(str){ $("#debug").append("<p>"+str+"</p>"); };
if(typeof WebSocket === 'undefined') {
alert("Your browser does not support websockets.")
}
/**
* Render templates.
*
* @param {String} The template to use `<p>Hello {{name}}</p>`
* @param {String} The data `{ name: 'Alex' }`
* @return {String} The rendered template
**/
function template(t, d) {
return t.replace(/{{([^}]*)}}/g, function(m, f, p, a) {
return d[f] || '';
@easierbycode
easierbycode / timeout.js
Created December 22, 2011 01:24 — forked from mxriverlynn/timeout.js
Timeout
Foo = {};
Foo.bar = function(){
alert("test");
}
setTimeout(Foo.bar, 1000); // 1 second later, alert's "test"
@easierbycode
easierbycode / manualcall.js
Created December 22, 2011 17:38 — forked from mxriverlynn/manualcall.js
search with backbone collections
var results = new SearchResults();
results.searchTerm = "some search term";
results.fetch({
success: someView.showTheResults
});
@easierbycode
easierbycode / fiddle.html
Created February 10, 2012 07:51 — forked from elijahmanor/fiddle.html
jQuery Private Data Should Stay Private
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
@easierbycode
easierbycode / monkey_patching.rb
Created February 29, 2012 04:25 — forked from bagwanpankaj/monkey_patching.rb
Monkey Patching done right
#first we create a subclass of class string
class MyString < String
end
MyString.new
# => ""
#now we are going to override this method by some Ruby magic
MyString.class_eval do
def empty?
describe('built-in matchers', function() {
describe('toBeTruthy', function() {
it('passes if subject is true', function() {
expect(true).toBeTruthy();
expect(false).not.toBeTruthy();
});
});
describe('toBeFalsy', function() {
it('passes if subject is false', function() {
@easierbycode
easierbycode / uri.js
Created April 22, 2012 20:53 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@easierbycode
easierbycode / gist:2731426
Created May 19, 2012 16:33 — forked from Chris-Murphy/gist:2394143
MapBlips abridged
var Blips = new Meteor.Collection("blips");
if (Meteor.is_client) {
var handle = Meteor.subscribe('blips', function () {});
var handleClient = Meteor.subscribe('blips_' + clientID, function () {});
Meteor.call('mapBlips', box, clientID, function (error, result){
BlipsClient = new Meteor.Collection('blips_' + clientID);
blips_client = BlipsClient.find({});
}
@easierbycode
easierbycode / basic_set_ops.rb
Created September 11, 2012 18:24 — forked from scottaj/basic_set_ops.rb
Set operations
require 'set'
# Union
Set[1,2,3] | Set[3,4,5]
#=> #{1,2,3,4,5}
# Intersection
Set[1,2,3] & Set[2,3,4,5]
#=> #{2,3}