This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Don’t Repeat Yourself (DRY) in Ruby on Rails | |
#DRY (Don’t Repeat Yourself) is a principle of Software Development to reducing repetition of information or codes. We can #apply DRY quite broadly to database schema, test plan, system, even documentation. And in this post, we will take example of DRY #in Ruby on Rails development. | |
#In particular case, if you find some methods whose definitions are more or less similar, only different by the method name, it #may use meta programming to simplify the things to make your model more clean and DRY. Consider this simple example where we #have an article with three states. | |
#Before | |
class Article < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Rails Logger Tricks | |
#Here are a few quick tricks for using the Rails logger. | |
#Save disk space by rotating logs in the config/environments/test.rb and config/environments/development.rb | |
config.logger = Logger.new(Rails.root.join("log",Rails.env + ".log"),3,5*1024*1024) | |
#which will rotate the log files every 5 megabytes and leave only the three most recent log files. This will limit the total spaces #used by the logs at 15 megabytes. | |
#To log to STDOUT while using the console use this trick: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 SublimeERb | |
TextMate Style ERB Block for Sublime Text | |
https://github.com/eddorre/SublimeERB | |
11. A Sublime Text 2/3 plugin to see git diff in gutter | |
http://www.jisaacks.com/gitgutter | |
10. Package control | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exporting your repository | |
Previously there was a tip that covered sharing changes but that included all of your repository’s history. | |
What if you just want to export a certain commit’s changes? Or just one folder? What if you wanted to make | |
an archive of the repository for backup? | |
Fear not, for Git can do all that and more. Thanks to Stack Overflow for providing with some helpful hints to add into this post. | |
If your need is to just make a quick backup of your repository, doing a git archive will help. So if you wanted to get | |
zip file packed with your repository’s files: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://blog.firmhouse.com/fancy-money-entry-for-your-rails-app-with-autonumeric-and-moneyrails | |
Creating fancy money entry for your Rails app | |
This week I was working on a client project where we wanted to implement a nice way of entering an amount of money. We wanted to replace a standard text input field with something like this: | |
Money entry sample | |
In the resulting implementation, when the user types the amount in the text box it automatically splits thousands and the decimal point. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Instructions | |
#Add the gems to your Gemfile: | |
gem 'fog' | |
gem 'carrierwave' | |
gem 'rmagick' # optional, for image resizing support | |
# Add the file './config/initializers/carrierwave.rb' for your CarrierWave configuration: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gzip on; | |
gzip_http_version 1.1; | |
gzip_disable "msie6"; | |
gzip_vary on; | |
gzip_min_length 1100; | |
gzip_buffers 64 8k; | |
gzip_comp_level 3; | |
gzip_proxied any; | |
gzip_types text/plain text/css application/x-javascript text/xml application/xml; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<CORSConfiguration> | |
<CORSRule> | |
<AllowedOrigin>http://www.example.com</AllowedOrigin> | |
<AllowedMethod>PUT</AllowedMethod> | |
<AllowedMethod>POST</AllowedMethod> | |
<AllowedMethod>DELETE</AllowedMethod> | |
<AllowedHeader>*</AllowedHeader> | |
</CORSRule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Asynchronous and deferred JavaScript execution explained | |
The HTML <script> element allows you to define when the JavaScript code in your page should start executing. The “async” and “defer” attributes were added to WebKit early September. Firefox has been supporting them quite a while already. Does your browser support the attributes? | |
Normal execution <script> | |
------------------------------- | |
This is the default behavior of the <script> element. Parsing of the HTML code pauses while the script is executing. For slow servers and heavy scripts this means that displaying the webpage will be delayed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The nginx: unrecognized service error means the startup scripts need to be created. | |
Fortunately the startup scripts have already been written. | |
We can fetch them with wget and set them up following these steps: | |
# Download nginx startup script | |
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh | |
# Move the script to the init.d directory & make executable | |
sudo mv init-deb.sh /etc/init.d/nginx |
OlderNewer