Skip to content

Instantly share code, notes, and snippets.

@thomsbg
thomsbg / gist:8847050
Created February 6, 2014 16:00
each_slice
<% data.stories.each_slice(4) do |chunk| %>
<div class="m-box">
<% chunk.each do |d| %>
<div class="m-boxes__quarter" style="background-image: url('<%= d.image %>');">
<h6><a href="<%= d.url %>" target="new"><%= d.headline %></a></h6>
</div>
<% end %>
</div>
<% end %>
<div style="width: 970px; margin: 0 auto; clear: both;">
<!-- ad markup goes here -->
</div>
@thomsbg
thomsbg / index.html
Last active August 29, 2015 14:01
Mid-body ad unit test bookmarklet
<a href="javascript:(function($) {var ad = $('<p>').css({ backgroundColor: 'red', height: '0' }); $('#article-body, .entry-body').first().find('p, h1, h2, h3, h4, h5, h6, blockquote').eq(2).before(ad); ad.animate({ height: '250px' }, 'fast'); })(jQuery)">Test mid-body ad</a>
<p>^---- Drag this to your bookmarks toolbar.</p>
<p>Click it on any chorus article page to insert a red box where the ad would appear.</p>
@thomsbg
thomsbg / snippet.json
Created September 11, 2014 18:14
content model
{
"startLength": 0,
"endLength": 394,
"ops": [
{
"value": "Quill Rich Text Editor",
"attributes": {
"size": "18px"
}
},
@thomsbg
thomsbg / rich-text-schema.yml
Created March 3, 2015 22:16
rich-text json-schema
$schema: 'http://json-schema.org/draft-04/schema#'
type: object
properties:
ops:
type: array
items:
oneOf:
- type: object
properties:
insert:
@thomsbg
thomsbg / pullquote.js
Last active August 29, 2015 14:28
pullquote quill format
{
type: 'embed',
tag: 'IFRAME',
add: function(node, data) {
node.classList.add('pullquote');
node.setAttribute('data-pullquote', data.value);
node.setAttribute('src', '/iframe/pullquote.html');
return node;
},
remove: function(node) {
@thomsbg
thomsbg / image.js
Created August 23, 2015 22:07
image quill format
{
type: 'embed',
tag: 'IFRAME',
add: function(node, value) {
node.classList.add('image');
node.setAttribute('data-src', value.src);
node.setAttribute('data-caption', value.caption);
node.setAttribute('src', '/iframe/image.html');
return node;
},
@thomsbg
thomsbg / snippet.rb
Created November 19, 2015 00:02
fix_nested_attributes_for_uniqueness.rb
def fix(records, params, matcher)
params = params.deep_dup
records.each do |record|
if p.any? { |attrs| attrs['id'].present? && attrs['id'].to_i == record.id }
next
elsif (new_attrs = p.detect { |attrs| attrs['id'].blank? && attrs[matcher].present? && attrs[matcher].to_i == record[matcher] })
new_attrs['id'] = record.id
else
p << { '_destroy' => true, 'id' => record.id }
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@thomsbg
thomsbg / compile_templates.js
Last active December 22, 2015 20:29
Loop through all the view prototype objects in a namespace, transforming their templateId into a template function.
var compileTemplates = function() {
_.each(App.Views, function(View) {
if (View.prototype.templateId) {
// The templateId references the id of a DOM element containing
// the content of the template
var html = jQuery('#' + View.prototype.templateId).html() || '';
View.prototype.template = _.template(html);
}
});
}