`
文章列表
UPDATE: (05/03/2013) 当前使用: #去掉所有的FactoryGirl. find . -type f -name *_spec.rb -print | xargs sed -ie 's/FactoryGirl\.//g' //Seems like Linux is being far too generous. -i 's/^[[:space:]]\{11\}//g' <-- makes it look like "s/^[[:space:]]\{11\}//g" is the extension given to & ...

shell script

select r.name, count(p.id) from persons as p join rides as r on p.fav_ride_id = r.id group by r.id order by count(p.id) desc limit 2; 一整就用到 $PWD $PATH $HOME The shell has variables to access arguments in the procedures, to define the environment and the like. Shell variables are: $1 # arg ...
一个关于如何在指定文件大于1GB后,自动删除的问题。 批处理代码如下: #!/bin/bash # 当/var/log/syslog大于1GB时 # 自动将其备份,并清空 # 注意这里awk的使用 if ! [ -f /var/log/syslog ] then echo "file not exist!" exit 1 fi if [ `ls -l /var/log/syslog|awk '{print $5}'` -gt $((1024*1024)) ] then cat /var/log/syslog >> ~/l ...
有时候需要在Linux下查看一个进程占用了那个端口,但是只知道进程大致的名称,比如要查看hadoop的namenode在哪个端口上运行,以便在eclipse中连接。 首先用ps命令查看进程的id: $ ps -ef | grep Name  其中每一行(很长的时候会占用若干行)的第二个字段就是进程的id。 当然,对于在java虚拟机中运行的进程,比如hadoop的守护进程,可以直接用jsp命令查看: $ jps | grep Name  或者已经知道进程的确切名称,可以用pidof查看: $ pidof Name  查看到进程id之后,使用netstat命令查看其占用的端口: ...
当前ruby1.9.3 rails 3.2.8,流行的文件上传插件是paperclip和carrierwave 然而,简单的这是需要上传个文件的话,可以用更容易的办法 <%= form_tag({:action => :upload}, :multipart => true) do %> <%= file_field_tag 'picture' %> <% end %> <%= form_for @person do |f| %> <%= f.file_field :picture %> < ...
def up connection.execute(%q{ alter table contests alter column prize type integer using cast(prize as integer), alter column price set default 200 }) end def up case ActiveRecord::Base.connection when ActiveRecord::ConnectionAdapters::PostgreSQLAd ...
# Create a structure with a name in Struct Struct.new("Customer", :name, :address) #=> Struct::Customer Struct::Customer.new("Dave", "123 Main") #=> #<struct Struct::Customer name="Dave", address="123 Main"> # Create a structur ...
class A class << self def class_name to_s end end end A.define_singleton_method(:who_am_i) do "I am: #{class_name}" end A.who_am_i # ==> "I am: A" guy = "Bob" guy.define_singleton_method(:hello) { "#{self}: Hello there! ...
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table_name}")
class Person < ActiveRecord::Base has_one :address, :as => :addressable end class Company < ActiveRecord::Base has_one :address, :as => :addressable end class Address < ActiveRecord::Base belongs_to :addressable, :polymorphic => true end Address 有adressable_id addr ...
http://stackoverflow.com/questions/457927/git-workflow-and-rebase-vs-merge-questions 引用 git fetch用来将自己本地的repo 更新到最新的。 但是fetch后,并不会显示到本地。  有两种办法, rebase 和 merge. if you want masterA => masterB => masterC => yourworkhere => (masterD and E merged) => HEAD then use merge if you want m ...
External PostgreSQL connections 1. To be able to reach the server remotely you have to add the following line into the file: /var/lib/pgsql/data/postgresql.conf: listen_addresses = '*' 2. PostgreSQL, by default, refuses all connections it receives from any remote address. You have to relax these ru ...
Rails 3 Installation sudo gem install rails postgres as db installation<>br/ $ sudo apt-get install postgresql Rails 3 App with postgres as database $ rails new pg -d postgres bundle installation It will install dependency gems & postgres adapter for db connection bundle install Here ...
require 'active_support/core_ext' YAML.parse("key: value").transform.to_xml
错误提示: 引用 I, [2012-09-04T08:52:02.594025 #3839]  INFO -- : listening on addr=0.0.0.0:3000 fd=5 I, [2012-09-04T08:52:02.594204 #3839]  INFO -- : worker=0 spawning... I, [2012-09-04T08:52:02.594679 #3839]  INFO -- : master process ready I, [2012-09-04T08:52:02.595505 #3841]  INFO -- : worker=0 spawned ...
Global site tag (gtag.js) - Google Analytics