Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
appendFontStyles : function() {
var style = $('<style />'),
headings = ['h1', 'h2', 'h3'];
_.each(Shining.fonts, function(font) {
_.each(headings, function(tag) {
style.append('.s-stage.h-' + font.klass + ' ' + tag + ' { font-family: "' + font.family + "\" }\n ");
});
style.append('.s-stage.p-' + font.klass + ' p { font-family: "' + font.family + "\" }\n ");
});
Shining.Player.el.prepend(style);
@juliocesar
juliocesar / gist:1003781
Created June 2, 2011 02:01
Safe insertion of text or HTML

Say we have a paragraph with some links in it:

<p>
  Foo bar foo bar foo bar <a href="foo">a link</a> and more text.
  Text text <a href="test">foo link</a>. More text bla bla.
</p>

This renders as:

Foo bar foo bar foo bar a link and more text. Text text foo link. More text bla bla.

@juliocesar
juliocesar / selection.js
Created May 23, 2011 06:11
Get the current selection in JS
function selection() {
return window.getSelection ? window.getSelection().toString() :
document.getSelection ? document.getSelection().toString() :
document.selection ? document.selection.createRange().text :
false;
}
ExpiresActive On
<VirtualHost *:80>
ServerName awesomebydesign.com
DocumentRoot /usr/local/awesomebydesign.com/current
Options -MultiViews
ErrorLog /usr/local/awesomebydesign.com/log/error.log
CustomLog /usr/local/awesomebydesign.com/log/access.log combined
ExpiresByType image/png "access plus 3 days"
ExpiresByType text/javascript "access plus 3 days"
AddOutputFilterByType DEFLATE text/html text/javascript
@juliocesar
juliocesar / gist:941624
Created April 26, 2011 01:18
Damn simple JavaScripts bundler for Sinatra
# Adjust the line that says Dir.chdir so it points to the path where your
# JavaScripts are stored.
#
# Usage:
# Instead of linking scripts one by one with <script> tags, as in:
# <script src="/js/jquery-1.5.2.min.js"></script>
# <script src="/js/underscore.js"></script>
# <script src="/js/backbone-min.js"></script>
#
# You can now go:
@juliocesar
juliocesar / best-localStorage-polyfill-evar.js
Created April 18, 2011 23:19
This is the best localStorage polyfill in the world
// I mean, seriously, localStorage is supported even by your mum. How about instead of
// casing the feature out, you give users in-memory (stale) storage instead?
// If they close your application, they deserve to lose data anyway.
// if (!('localStorage' in window)) {
if (!Modernizr.localstorage) {
window.localStorage = {
_data : {},
setItem : function(id, val) { return this._data[id] = String(val); },
getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
<STYLE>
button { border-color: red; background-color: white; font-size: 20px; }
</STYLE>
<BUTTON>CSS1 RLZ</BUTTON>

Run this closure as a patch to jQuery.fn.show to make it fire an event when called:

(function(show) { jQuery.fn.show = function() { return show.apply(this, arguments).trigger('showing'); } })(jQuery.fn.show)

E.g.:

$('h1:first')
  .bind('showing', function() { console.log('yeah'); });
  .hide()

.show();

@juliocesar
juliocesar / localstorage.js
Created April 8, 2011 00:44
Backbone.js localStorage if specified
// Generate four random hex digits.
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// Generate a pseudo-GUID by concatenating random hexadecimal.
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
};
require 'steak'
require 'capybara'
require 'capybara/dsl'
require 'rack/test'
RSpec.configure do |config|
def app
Capybara.app
end
config.include Capybara