Skip to content

Instantly share code, notes, and snippets.

View nicinabox's full-sized avatar

Nic Haynes nicinabox

View GitHub Profile
@nicinabox
nicinabox / controller.rb
Created March 6, 2012 17:53
Setting i18n translations in Refinery
# In a controller
# This is not necessary when using the view code below
::I18n.locale = params[:locale]
<h4>July<br /><span>21</span></h4>
<time>July 21, 7-9pm</time>
<h2>New Voices/new Vistas Muntu’s Summer Concert And Gala</h2>
<h3>Harris Theatre For Music And Dance Millennium Park</h3>
<p>At 40, Muntu continues to explore the future of African &amp; African American dance. This concert will feature groundbreaking new work by choreographer Jeffery Page who has worked with Beyonce and was a lead dancer in the Broadway production ‘Fela.’</p>
<p>Gala dinner and reception following the performance on the Rooftop Terrace.</p>
<a class="button" href="#">Buy Tickets</a>
@nicinabox
nicinabox / 1_README.md
Created March 21, 2012 19:46
Schedule nightly backups to Amazon S3 with Ruby and Whenever

Install gems

gem install whenever mysql2 pony ruby-s3cmd

Configure S3 & schedule.rb

Go ahead and create your backup bucket on S3 now. Configure whenvever to do your backups at a time when server load will be low (I picked 2:00 am).

Update mysql_backup.rb configuration

<%= @blog_posts.each do |post| %>
<%= post.published_at.strtime('%B %d, %Y') %>
<%= post.title %>
<% end %>
@nicinabox
nicinabox / application_helper.rb
Created April 10, 2012 00:14
Plot elements on a circle with Ruby
def angle_to_radians(angle)
Math::PI * (angle * -1.0 / 180)
end
def radians_to_cartesian(radian, radius, offset_x, offset_y)
{
:x => (offset_x + (radius * Math::sin(radian))).round,
:y => (offset_y + (radius * Math::cos(radian))).round
}
end
@nicinabox
nicinabox / 1_migration.md
Created April 23, 2012 16:14
Add a key image to Refinery

Create migrations

rails g migration add_key_image_to_refinery_page key_image_id:integer

rake db:migrate

Override Page model

rake refinery:override model=refinery/page

@nicinabox
nicinabox / style.scss
Last active October 3, 2015 15:58
Center UL
ul {
position: relative;
float: left;
left: 50%;
li {
position: relative;
float: left;
left: -50%;
}
}
@nicinabox
nicinabox / accordion.js
Created May 2, 2012 21:58
Use an accordion dynamically in a Refinery page
if ($('#main').hasClass('accordion')) {
$('#main .content h3').each(function(index) {
content = $(this).nextUntil('h1, h2, h3')
content.wrapAll('<section />')
});
}
$('#main.accordion .content').accordion({
header: 'h3',
collapsible: true,
@nicinabox
nicinabox / gist:2586814
Created May 3, 2012 16:04
Load image with callback
var loadImage = function($img, callback) {
var image;
image = new Image();
return $img.load(function() {
if (typeof callback === 'function') {
callback(this);
}
return this;
});
};
@nicinabox
nicinabox / gist:2770226
Created May 22, 2012 16:55
Regex to fix Sequel Pro's CSV formatting
[\n]+([^\d])