Skip to content

Instantly share code, notes, and snippets.

View marcusmalmberg's full-sized avatar

Marcus Malmberg marcusmalmberg

View GitHub Profile
// Bootstrap Mid-Small - col-ms-* - the missing grid set for Bootstrap3.
//
// This is a hack to fill the gap between 480 and 767 pixels - a missing range
// in the bootstrap responsive grid structure. Use these classes to style pages
// on cellphones when they transition from portrait to landscape.
//
// Contains:
// Columns, Offsets, Pushes, Pulls for the Mid-Small layout
// Visibility classes for the Mid-Small layout
// Redefined visibility classes for the Extra Small layout
.col-ms-1,
.col-ms-2,
.col-ms-3,
.col-ms-4,
.col-ms-5,
.col-ms-6,
.col-ms-7,
.col-ms-8,
.col-ms-9,
.col-ms-10,
# db/migrate/20111218135715_globalize_models.rb
class GlobalizeModels < ActiveRecord::Migration
def up
NewsItem.create_translation_table!(
{:title => :string, :body => :text},
{:migrate_data => true}
)
end
@marcusmalmberg
marcusmalmberg / _readme.md
Created November 23, 2012 00:01
How to serve a vcard properly from amazon s3 in a rails app

This gist shows how to download a vcard with mime-type

It's easy to provide a simple link to download a vcard. The problem is that normal devices doesn't recognize the downloaded vcard and will most often just render them in the browser as plain text.

This gist is an example of how you can download the vcard with proper mime-type, which allows the device to recognize it as a vcard.

Prerequisites

This example assumes that you have a model Contact with a connected vcard. This example was built using a simple carrierwave uploader to upload the vcard to amazon s3.

@marcusmalmberg
marcusmalmberg / _readme.md
Created November 14, 2012 18:30
Easy way to have full control of asset precompilation

What is this?

It's a way to better handle page specific css and javascript files. It gives you full control of which files are included and compiled where. This is a way to easily minimize the file request while still keeping out unnecessary stuff from the files, without you as a developer need to edit environment files.

Why not controller specific files?

guides.rubyonrails.org mentions a way to easily handle controller specific stylesheets and javascript files. Like:

javascript_include_tag params[:controller]

Sometimes that's not enough or it will break because of some gem you have installed, and that's when this method comes in handy.

@marcusmalmberg
marcusmalmberg / _stuff.txt
Created November 14, 2012 16:51
Useful stuff for project
Permalinks/Pretty urls:
https://github.com/norman/friendly_id
http://railscasts.com/episodes/314-pretty-urls-with-friendlyid
Globalization (untested):
https://github.com/svenfuchs/globalize3
CMS:
http://activeadmin.info/
@marcusmalmberg
marcusmalmberg / active_admin_can_can.rb
Created November 14, 2012 16:48
ActiveAdmin with CanCan
module ActiveAdminCanCan
def active_admin_collection
super.accessible_by current_ability
end
def resource
resource = super
authorize! permission, resource
resource
end
@marcusmalmberg
marcusmalmberg / heroku-backup.md
Created November 14, 2012 16:45
Backup/Restore heroku database
@marcusmalmberg
marcusmalmberg / CarrierWave.md
Last active June 14, 2021 23:22
Guide to setup CarrierWave which will upload a file to Amazon S3 in production environment and use local storage in development and test

CarrierWave home

https://github.com/jnicklas/carrierwave

This example will create an uploader that will upload a file stored in a model Model. The file will be stored locally in development and test environment and will use Amazon S3 in production.

CarrierWave installation

First add the gems.

@marcusmalmberg
marcusmalmberg / default.rb
Created July 4, 2012 15:24
create_swapfile recipe
swapfile path = '/mnt/swapfile'
swapfile_bs = '1M'
swapfile_count = '1024'
execute "create_swapfile" do
Chef::Log.info "About to create swapfile if it doesn't exist"
command %Q{
sudo dd if=/dev/zero of=#{swapfile_path} bs=#{swapfile_bs} count=#{swapfile_count} && \
sudo mkswap #{swapfile_path} && \
sudo swapon #{swapfile_path}