Ubuntu change the default editor
Ubuntu change the default editor
update-alternatives --config editor
ShareSnippets е публично хранилище за програмен код. Лесно можете да съберете собствена колекция от отрязъци от код, да ги систематизирате с етикети, ключови думи, и да ги споделите (или ако не искате, да ги запазите за себе си!)
Уеб Адрес: http://blog.jivkobg.com
Добавени отрязъци: 29
Проекти: 3
Линкове: 2
update-alternatives --config editor
def current_year Time.now.strftime('%Y') end
"...Всички права запазени <%= current_year %> ...."
rails _1.2.6_ името_на_проекта
map.resources :news -> map.resources :news, :singular => :news_instance news_path() /news new_news_instance_path() /news/new news_instance_path(1) /news/1 edit_news_instance_path(1) /news/1;edit #edit <% form_for(@news, :url=> news_instance_path(@news)) do |f| %> ...... if @news.save format.html { redirect_to news_instance_path(@news) } ......
sudo gem install fastercsv
require 'rubygems' require 'fastercsv' FasterCSV.foreach('./imAreas.csv') do |row| e1 = row[0] e2 = row[2] e3 = row[3] ......... end
Sitemap: http://www.yoursite.com/sitemap.xml
cd vendor/plugins svn export https://secure.near-time.com/svn/plugins/trunk/tiny_mce
rake tiny_mce:scripts:install
<%= javascript_include_tiny_mce_if_used %> <%= tiny_mce if using_tiny_mce? %>
class Admin::BaseController < ApplicationController layout 'admin' uses_tiny_mce(:options => {:theme => 'advanced', :browsers => %w{msie gecko}, :theme_advanced_toolbar_location => "top", :theme_advanced_toolbar_align => "left", :theme_advanced_resizing => true, :theme_advanced_resize_horizontal => false, :paste_auto_cleanup_on_paste => true, :theme_advanced_buttons1 => %w{formatselect fontselect fontsizeselect bold italic underline strikethrough separator justifyleft justifycenter justifyright indent outdent separator bullist numlist forecolor backcolor separator link unlink image undo redo}, :theme_advanced_buttons2 => [], :theme_advanced_buttons3 => [], :plugins => %w{contextmenu paste}}, :only => [:new, :edit, :show, :index]) .....
Redirect 301 /example_dir http://www.domain_example.com
sudo perl -MCPAN -e 'install DBD::mysql'
dbdimp.c: In function 'mysql_dr_connect': dbdimp.c:1677: error: 'ulong' undeclared (first use in this function) dbdimp.c:1677: error: (Each undeclared identifier is reported only once dbdimp.c:1677: error: for each function it appears in.) dbdimp.c:1677: error: parse error before numeric constant make: *** [dbdimp.o] Error 1
typedef unsigned long ulong;
:integer :float :datetime :date :timestamp :time :text :string :binary :boolean
<%= link_to_unless request.env['HTTP_REFERER'].nil?, 'back', request.env['HTTP_REFERER']%>
<%= link_to 'back', request.env['HTTP_REFERER'] unless request.env['HTTP_REFERER'].nil?%>
require ‘gettext/rails’ class ApplicationController < ActionController::Base
require ‘gettext/rails’
.... begin ENV["RAILS_ENV"] = @config[:db_mode] require ‘config/boot.rb’ require ‘config/environment.rb’ # require ‘app/controllers/application.rb’ ....
http://manuals.rubyonrails.com/read/chapter/105
http://wiki.dreamhost.com/RubyGems
gem install -y radiant Bulk updating Gem source index for: http://gems.rubyforge.org Killed
rm -rf /home/USERNAME/.gems/source_cache
RailsFCGIHandler.process! nil, 10 class RailsFCGIHandler private def frao_handler(signal) dispatcher_log :info, "asked to terminate immediately" dispatcher_log :info, "frao handler working its magic!" restart_handler(signal) end alias_method :exit_now_handler, :frao_handler end
perl -pi -w -e 's/search/replace/g;' *.php -е - изпълнява съответният код -i - редактира на място -w - съобщения при записване -p - цикъл (loop)
#!/usr/bin/env ruby require File.dirname(__FILE__) + "/../config/environment" require 'fcgi_handler' class RailsFCGIHandler private def frao_handler(signal) dispatcher_log :info, "asked to terminate immediately" dispatcher_log :info, "frao handler working its magic!" restart_handler(signal) end alias_method :exit_now_handler, :frao_handler end RailsFCGIHandler.process!
products = Array.new products << {'name'=>'one', 'price'=>100} products << {'name'=>'two', 'price'=>200} products << {'name'=>'three', 'price'=>50} products.sort_by { |p| p['name'] } products.sort_by { |p| p['price'] }
create_table :images do |t|
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
t.column :user_id, :integer
t.column :asset_id, :integer
t.column :asset_type, :string
end
t.column :asset_id, :integer
t.column :asset_type, :string
class Image < ActiveRecord::Base belongs_to :asset, :polymorphic => true, :dependent => :destroy .....
class Link < ActiveRecord::Base has_one :image, :class_name => 'Image', :as => :asset, :dependent => :destroy ....
class LinksController < ApplicationController def new @link = Link.new end def create @link = Link.new(params[:link]) if !params[:image][:uploaded_data].blank? @image = Image.new(params[:image]) @link.image = @image end if @link.save flash[:notice] = 'Линка е добавен успешно !' redirect_to :action => 'list' else render :action => 'new' end end def edit @link = Link.find(params[:id]) @image = @link.image end def update @link = Link.find(params[:id]) @link.attributes = params[:link] if !params[:image][:uploaded_data].blank? @image = Image.new(params[:image]) @link.image = @image end if @link.update_attributes(params[:link]) flash[:notice] = 'Линка беше променен !' redirect_to :action => 'list' else render :action => 'edit' end end
has_attachment :content_type => :image, :storage => :file_system, :max_size => 200.kilobytes, :resize_to => '320x240>', :thumbnails => { :thumb => '100x100>' } def validate errors.add("empty", "Изберете снимка на проекта") unless self.filename unless self.filename == nil # Images should only be GIF, JPEG, or PNG [:content_type].each do |attr_name| enum = attachment_options[attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add("type","Файла който сте избрал е различен от JPEG, PNG или GIF") end end # Images should be less than 5 MB [:size].each do |attr_name| enum = attachment_options[attr_name] unless enum.nil? || enum.include?(send(attr_name)) errors.add("size", "Файла който сте избрал е с големина по-голяма от максималната 200 KB") end end end end
<%= error_message_on 'image', 'empty' %> <%= error_message_on 'image', 'size' %> <%= error_message_on 'image', 'type' %>