Skip to content

Instantly share code, notes, and snippets.

View sergi's full-sized avatar
🎯
Focusing

Sergi Mansilla sergi

🎯
Focusing
View GitHub Profile
@sergi
sergi / insertNodeAtSelection.js
Created June 9, 2009 20:28
Inserts node at selection (Gecko)
insertNodeAtSelection : function(win, insertNode, _container, _pos)
{
// get current selection
var sel = this._getSelection(); var doc = this._getDoc();
// get the first range of the selection (there's almost always only
// one range)
var range = sel.getRangeAt(0);
// deselect everything
- simple
- public over private
- personal vanity
- internet is global
- permalinks
- one important item per page
- don't break the browser
- don't wanker in technology
- a medium is not a grande
- break convention for your users
@sergi
sergi / example.js
Created October 27, 2009 20:40 — forked from Gozala/README.md
exports.example = function(a, b) {
['This is a function foo which is supposed to do something.\n\
But the best thing is that it has nice documentation in it.\
@param {String} a first argument\
@param {String} b second argument\
@returns {String} Concatinated string literal']
return [a, b].join(" ");
};
/**
* Converts relative UTF8 characters (C-style) to
* JavaScript friendly utf chars
**/
var str = "";
var relativeTo = 0x300;
[0x90,0x99,0xaa,0xaf,0xb9,0xca,0x7e,0x87,
0x84,0xc4,0xbe,0xad,0xb6,0x85,0xb5,0x8a,
0xc2,0xb8,0xbb,0xb3,0xbd,0xba,0xc7,0xcb,
YUI({ debug: true,
filter: 'debug',
logInclude: { event: true, attribute: true },
timeout: 10000 }).use("node", "attribute", "dd-drag", "dd-drop", "dd-constrain", function(Y) {
Y.Node.prototype.toString = function() { … } // This works
Y.DOM.hasClass = function(node, className) { … } // This doesn't
// Here goes my own code
function Test(cfg) {
Test.superclass.constructor.apply(this, arguments);
this.initializer(cfg);
};
Y.extend(Test, Y.Base, {
initializer: function(config) {
this.addAttrs({
items: {
value: []
@sergi
sergi / hex2rgb.js
Created March 16, 2010 16:20
Converts hexadecimal colors to RGB color tuples
var hex2rgb = function(color) {
var r = color.match(/^#(([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2}))$/i);
if (!r) return [0, 0, 0, 255];
return [parseInt(r[2], 16),
parseInt(r[3], 16),
parseInt(r[4], 16), 255];
}
var Class1 = function() {
Class1.superclass.constructor.call(this, config);
}
Class1.NAME = "class1";
Class1.ATTRS = {
//Several Attributes here
}
Y.extend(Class1, Y.Base, {
/*
AST tree generated from parsing the following Design By Numbers program:
paper 30
repeat A 0 300
{
pen 50
line 0 55 100 55
@sergi
sergi / gist:647062
Created October 26, 2010 15:05
YUI Loader example
YUI({
debug: true,
groups: {
app: {
combine: false,
base: "src/",
modules: {
module1: {
path: "module1.js",
requires: ["module2"]