Skip to content

Instantly share code, notes, and snippets.

View DimitarChristoff's full-sized avatar

Dimitar Christoff DimitarChristoff

View GitHub Profile
@DimitarChristoff
DimitarChristoff / Browser.features.base64.js
Created February 10, 2011 21:21
Feature detect base64 support for images in mootools
(function() {
Browser.Features.base64 = null;
var callback = function() {
Browser.Features.base64 = this.width == 1 && this.height == 1;
// alert(Browser.Features.base64); // true || false
};
var img = new Image(), img = document.id(img) || new Element("img");
img.onload = img.onerror = img.onabort = callback;
// 1x1 px gif to test with
@jlong
jlong / uri.js
Created April 20, 2012 13:29
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"
@nzakas
nzakas / noanon.md
Created June 8, 2012 21:19
Avoiding "new anonfn"

JSLint doesn't like using new function. This makes sense, because you're just creating a singleton, and so there's no point in using a constructor for that. If you have something like this:

var NowWithClosures = Backbone.Model.extend(new function(){
    var x = 1;
    this.initialize = function(){
        console.log('init');
    };
    this.AddOneToX = function(){
 x++;
@haf
haf / install-git.sh
Created August 22, 2012 14:38
Installing git and git-subtree from source in ubuntu as packages
# use with: curl -L https://raw.github.com/gist/3426227 | bash
# get git binary, then git with git
sudo apt-get install git -y
git clone https://github.com/git/git.git
# remove your binary/package
sudo apt-get remove git -y
sudo apt-get install make checkinstall libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc -y
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
var pop = new new Class({
Implements: [Options, Events],
options: {
// onBlock: Function.from(),
// onClose: Function.from(),
// onOpen: Function.from(),
width: 1024,
height: 768,
@timwienk
timwienk / irc-notify.js
Last active January 27, 2017 17:50
Simple IRC notify script, sic (http://tools.suckless.org/sic) inspired.
#!/usr/bin/env node
"use strict"
var connection = null,
buffer = '',
listeners = {};
var options = {
host: 'chat.freenode.net',
port: 6667,
@cobyism
cobyism / gh-pages-deploy.md
Last active May 7, 2024 18:46
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@getify
getify / 1.js
Last active December 14, 2015 18:38
requestEachAnimationFrame hopeful-fill.
(function(){
var
rAF = (window.requestAnimationFrame || window.msRequestAnimationFrame ||
window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
window.oRequestAnimationFrame),
cAF = (window.cancelAnimationFrame ||
window.msCancelAnimationFrame || window.msCancelRequestAnimationFrame ||
window.mozCancelAnimationFrame || window.mozCancelRequestAnimationFrame ||
window.webkitCancelAnimationFrame || window.webkitCancelRequestAnimationFrame ||
window.oCancelAnimationFrame || window.oCancelRequestAnimationFrame),
@addyosmani
addyosmani / mediatorExample.md
Last active December 15, 2015 01:59
Mediator with Backbone 0.9.10

The Mediator pattern enables communication (mediation) between views using a mediator object.In the latest version of Backbone, the Backbone object itself can be used as a mediator without the need of a seperate helper.

In the following example, triggerSomething in our ToolbarView uses the global event-bus on the Backbone object to broadcast an application wide event somethingHappened with data.

// First view
var ToolbarView = Backbone.View.extend({
  className: ".toolbar",
  events: {
    "click .button":   "triggerSomething"