Skip to content

Instantly share code, notes, and snippets.

@romansklenar
romansklenar / db.rake
Created April 1, 2015 18:08
Useful rake task for maintain PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc 'Maintains database by running command as ANALYZE, VACUUM and REINDEX'
task maintain: :environment do
verbose = ENV['VERBOSE'].present?
connection = ActiveRecord::Base.connection
puts "Maintaining database #{connection.current_database} ..."
connection.execute("VACUUM FULL #{'VERBOSE' if verbose}")
@averyvery
averyvery / load-view-specific-css.rb
Last active October 30, 2017 14:27
Load view-specific CSS in Rails
def view_css
path = "views/#{params[:controller]}/#{params[:action]}"
stylesheet_link_tag(path) unless Rails.application.assets.find_asset(path).nil?
end
class @GoogleAnalytics
@load: ->
# Load the analytics code
window['GoogleAnalyticsObject'] = 'ga'
window['ga'] = window['ga'] || ->
(window['ga'].q = window['ga'].q || []).push arguments
window['ga'].l = 1 * new Date()
# Add the script
@stephen-puiszis
stephen-puiszis / analytics.js.coffee
Created October 18, 2014 18:23
Turbolinks / Google Analytics Integration using new analytics.js library. Uses Gon to pass Rails settings variables to the coffescript.
# google_analytics.js.coffee
class @GoogleAnalytics
@load: ->
window['GoogleAnalyticsObject'] = 'ga'
window['ga'] = window['ga'] || ->
(window['ga'].q = window['ga'].q || []).push arguments
window['ga'].l = 1 * new Date()
@addyosmani
addyosmani / README.md
Last active July 2, 2025 14:29 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@remino
remino / compression.rb
Created September 3, 2014 03:58
Ruby on Rails: Minify HTML, CSS, & JS, and compress with gzip https://remino.net/rails-html-css-js-gzip-compression/
# config/initializers/compression.rb
Rails.application.configure do
# Use environment names or environment variables:
# break unless Rails.env.production?
break unless ENV['ENABLE_COMPRESSION'] == '1'
# Strip all comments from JavaScript files, even copyright notices.
# By doing so, you are legally required to acknowledge
# the use of the software somewhere in your Web site or app:
module Cancelerizer
def cancel arg
Sidekiq::ScheduledSet.new.each do |job|
(klass, method, args) = YAML.load job.args.first
if self == klass and args.first == arg
job.delete
end
end
end
end
@stereodenis
stereodenis / gist:d5749a0f17b1b53b5963
Last active August 10, 2021 17:00
social meta tags helper ruby on rails 4
def social_meta_tags
title = "#{(content_for?(:title) ? (strip_tags(content_for(:title)).html_safe + ' / ') : '')}#{t('project_title')}"
description = content_for?(:description) ? content_for(:description) : ''
image = if @doc.present?
image_url(@doc.cover_photo.cover.url)
elsif @main.present?
image_url(@main.cover_photo.cover.url)
else
''
end
@rob-murray
rob-murray / parse_pc_seed_data.rb
Last active December 12, 2017 03:40
Parse some csv data and write to a seed file for Rails
# Parse a CSV file reading certain attributes and outputting to Rails
# #create format that can be used as seed data.
#
# Not particularly good code but will do for now.
#
# Usage:
# $ ruby parse_pc_seed_data.rb
#
require 'csv'
require 'awesome_print'
@lassebunk
lassebunk / dragonfly_tasks.rake
Last active September 14, 2022 07:18
Migrate all Dragonfly images to Amazon S3 using rake task
# This will move all images and other Dragonfly assets from your local server file system to Amazon S3.
namespace :dragonfly do
task :migrate_to_s3 => :environment do
# Adjust this line to meet your needs:
{ Product => [:image_uid, :other_uid], Page => :image_uid }.each do |klass, col|
puts "Migrating #{klass.table_name}..."
Array(col).each do |col|
klass.where("#{col} != ''").find_each do |instance|
begin