Eduardo Russo was tired of complex favicon creation and created his own favicon generator. It's really easy and allows a lot of image editing before rendering the favicons, in all needed sizes, formats and with the HTML needed to include them!
In Rails applications with Haml:
/public
app/views/layouts/_favicon.html
= render 'layouts/favicon'
to <head>
in your application layout(s)... and you're all...
RulersGuides.js is a Javascript library which enables Photoshop-like rulers and guides interface on a web page
Also available as a bookmarklet.
pngquant is a command-line utility and a library for converting 24/32-bit PNG images to paletted (8-bit) PNGs.
The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency.
An annoying part of using font icons is that the icons usually need to live in the DOM. This is a step back from the time when we defined raster icons with background-image
, in the CSS.
It doesn't have to be that way.
Copy the attached file font-awesome-sass.css.sass
to your assets (we recommend /vendor/asset-libs/font-awesome-sass
).
You can now use Font Awesome icons from your Sass files:
@import font-awesome-sass
...
In Ruby, classes and modules are called constants. This card explains how Ruby resolves the meaning of a constant.
E. g. in the following example, Array
could mean either Foo::Array
or simply Array
:
class Foo
def list
Array.new
end
end
What Ruby does here is to see if the name Array
makes sense inside of Foo::
, and if that fails, resolves it to ::Array
(without a namespace).
This is relevant for old Ruby versions. Ruby 2.5+ removes top-level constant lookup whi...
CarrierWave attachments have two distinct methods #url
and #path
which appear to behave the same:
document.file.url # => /storage/documents/4/letter.doc
document.file.path # => /storage/documents/4/letter.doc
However, starting with CarrierWave 0.9, #url
will properly escape high-ASCII characters:
document.file.url # => /storage/documents/4/h%C3%BCte.doc
document.file.path # => /storage/documents/4/hüte.doc
So always use #url
if you mean an actual URL (e.g. to display an <img>
). But use #path
if y...
Assert rmagick
provision ...
Gemfile
gem 'rmagick', '2.13.2' # at this moment the latest stable version
config/initializer/carrierwave.rb
require 'carrierwave/processing/rmagick'
... and define a custom processor
MyUploader.rb
class MyUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
def cover
manipulate! do |frame, index|
frame if index.zero? # take only the first page of the file
end
end
version :preview do
process :cover
process :resize_to_fit => [310,...
# Attach a file
#
# Example:
#
# Company.new.logo = File.new…
#
# Given the file "…" was attached as logo to the company above
#
#
# Example:
#
# class Gallery
# has_many :images, :as => :owner
# end
#
# class Image
# belongs_to :owner, polymorphic: true
# end
#
# # so container = Image.new; container.file = File.new… , container.owner = object
#
# Given the file "…" was attached as Image/file to the company above
#
#
# Example:
#
# Set updated_at with
#
# Given … above at "2011-11-11 11:11"
#
Say you have a User
with a Carrierwave attribute #avatar
:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
When whitelisting the avatar
field in the controller, you might do this:
params[:user].permit(:avatar)
But you probably want this:
params[:user].permit(:avatar, :avatar_cache, :remove_avatar)
In this example:
:avatar_cache
allows a newly upload image to persist through form roundtrips in the case of validation errors (something that isn't possibl...When I upgraded from 0.5.4 PDFKit deadlocked or crashed when an ApplicationController::RouteError occured. If this error happens only because of a broken image link you probably still wan't the page to render and get a PDF with a "missing image placeholder" instead.
I don't know yet in which version (0.5.2, 0.5.3 or 0.5.4) the bug was built in. At the moment I'm doing fine with 0.5.1 and I didn't evaluate any other versions yet.
I will update this card as soon as I know further information (State 4th Nov. 2013).
Ubuntu 12.04 LTS x64, Ruby 1.8.7, Rails 2.13, PDFKit 0.5.4, Phusion Passenger Apache 2
I ran into this, when I started using passenger to deal with the Single Thread Issue which caused my webrick to deadlock when an ActionController::RoutingError (No route matches "...")
occurred.
(1) assert dependencies are installed
sudo aptitude install openssl build-essential xorg libssl-dev
(2) only for 64bits OS Run one by one the follo...
Awesome Sass plugin to experiment with Subtle Patterns based textures. It automatically removes the base color from the pattern, leaving a semi-transparent texture that you can tint in any color you want. It also has switches to invert the pattern.
@include texture(green, 34, 0); // color, texture-number, 0=inverted or 1=normal
If you have ever done this manually you know how much pain this can safe you. Check it out!
You might come to a situation where you want to retroactively change a version or add a new one. You can use the recreate_versions! method to recreate the versions from the base file. This uses a naive approach which will re-upload and process the specified version or all versions, if none is passed as an argument.
Call recreate_versions!
on a mounted uploader.
A common usecase
User.all.each { |user| user.avatar.r...
Did you know you can color your line-throughs or underline, or make them wavy like spell-checkers do?
For all late night coders:
The program "redshift" changes your monitors' white balance according to your position on the planet and your local time. This is supposed to put less strain on your eyeballs than staring at a "daylight white" screen all day and night.
The program is in the Ubuntu repositories, so a simple "sudo apt-get install gtk-redshift" transfers it onto your hard drive.
I find the effect rather pleasing and so I have set the following alias on my computer:
alias rdshft='gtk-redshift -l 48.3714407:10.8982552 -t 6500:4200 &'...
Using CSS sprites for background images is a technique for optimizing page load time by combining smaller images into a larger image sprite.
There are ongoing arguments on how useful this still is, as modern browsers become more comfortable to load images in parallel. However, many major websites still use them, for example amazon, [facebook](...
If you save your uploads to a made up directory like "RAILS_ROOT/uploads"
, this directory goes away after every deploy (since every release gets a new). Also this directory is not shared between multiple application servers, so your uploads are randomly saved to one local filesystem or another. Fixing this afterwards is a lot of fun.
Only two folders are, by default, shared between our application servers and deployments: "RAILS_ROOT/storage"
and `"RAILS...
If you need to capture signatures on an IPad or similar device, you can use Thomas J Bradley's excellent Signature Pad plugin for jQuery.
To implement, just follow the steps on the Github page.
If you have a model Signature
with name: string, signature: text
, you can use it with regular rails form like this:
- form_for @signature, :html => { :class => 'signature_form' } do |form|
%dl
%dt
= form...
Ruby has two different ways to match the start and the end of a text:
^
(Start of line) and $
(End of line)\A
(Start of string) and \z
(End of string)Most often you want to use \A and \z.
Here is a short example in which we want to validate the content type of a file attachment. Normally we would not expect content_type_1
to be a valid content type with the used regular expression image\/(jpeg|png)
. But as ^
and $
will match lines, it matches both content_type_1
and content_type_2
. Using \A
and \z
will wo...
Awesome color schemes for RubyMine, Sublime Text 2 and other editors.
To install the themes into your Rubymine, copy intellij-themes/*.xml
from the repository to your local ~/.RubyMine40/config/colors
. Then restart RubyMine.
Enjoy!
jquery-timing is a very useful jquery plugin that helps to remove lots of nested anonymous functions. It's API provides you some methods that help you to write readable and understandable method chains. See yourself:
// before
$('.some').show().children().doThat();
window.setTimeout(function(){
$('some').children().doSomething().hide(function() {
window.setTimeout(function() {
otherStuffToDo();
}, 1000);
});
}, 500);
// after
$('.some').s...
If - for whatever reason - you have to render stylesheets dynamically, the following snippet might be of help. It emulates what "sprockets" would to when precompiling your assets, and give your stylesheets access to all the regular bells and whistles (like asset_path
, proper @import
s etc):
class DynamicStylesheetsController < ApplicationController
def show
logical_path = RELATIVE_PATH_TO_YOUR_TEMPLATE
path = File.join(Rails.root, logical_path)
template = Sass::Rails::SassTemplate.new(path)
environment = ...
If you have a PNG and want to know a pixel's alpha channel value, you can use Gimp:
Shift
key while clicking the pixelA window will appear, containing color information, including the alpha channel.
imgAreaSelect is a jQuery plugin for selecting a rectangular area of an image. It allows web developers to easily implement image cropping functionality, as well as other user interface features, such as photo notes (like those on Flickr).