Use rsync.
E.g.
rsync -a /source/dir/ /destination/dir/
See:
http://unix.stackexchange.com/questions/9899/how-to-overwrite-target-files-with-mv
Use rsync.
E.g.
rsync -a /source/dir/ /destination/dir/
See:
http://unix.stackexchange.com/questions/9899/how-to-overwrite-target-files-with-mv
Need to stop a running script in mid-stride and check/change variables?
Here’s how:
1. add Pry
require ‘pry’
2. add an Exception handler
rescue Exception => exception
binding.pry
end
Now just use Ctrl C (on a Mac, Unix and Linux) and you’ll exit out with a debugger command prompt.
And exit pry permanently with:
!!!
Passenger is an application server for Ruby (Rack) and Python (WSGI) apps.
Some notes on installing it:
https://www.phusionpassenger.com/download
Ignore the docs that suggest:
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
Instead use:
gem install passenger
passenger-install-apache2-module
Then paste the LoadModule code it spits out at the end into your Apache conf file.
Test whether Passenger has installed by running:
curl -sI localhost | grep ^Server
and check for the “Phusion_Passenger” signature. E.g.
Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Phusion_Passenger/4.0.5 mod_ssl/2.2.22 OpenSSL/0.9.8x
If you need to uninstall Passenger using sudo then:
$ sudo gem uninstall passenger
And a discussion on whether to use rvmsudo or not here:
https://groups.google.com/forum/#!topic/rubyversionmanager/9dnmAsTiHR4
In short, https://www.phusionpassenger.com/download
suggests using sudo
but the rvm page suggests not:
https://rvm.io/integration/passenger
Note:
If you get a warning doing the passenger install apache2 module like this:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
Warning: can not check /etc/sudoers
for secure_path
, falling back to call via /usr/bin/env
, this breaks rules from /etc/sudoers
. Run:
export rvmsudo_secure_path=1
Then run:
export rvmsudo_secure_path=1
and:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
(remember to run rvm requirements
afterwards)
On the Mac the Apache conf and restart commands go like this:
[~]$ sudo vim /etc/apache2/httpd.conf
[~]$ sudo apachectl restart
See also:
https://developer.apple.com/library/mac/#featuredarticles/PhusionRails/_index.html
and this very useful guide:
Passenger is an application server for Ruby (Rack) and Python (WSGI) apps.
Some notes on installing it:
https://www.phusionpassenger.com/download
Ignore the docs that suggest:
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
Instead use:
gem install passenger
should be sufficient and rvm.io suggests just running:
passenger-install-apache2-module
See also:
http://stackoverflow.com/questions/17245105/passenger-module-fails-to-install
and
http://stackoverflow.com/questions/17248660/installing-passenger-use-sudo-rvmsudo-or-nothing
Then, paste the LoadModule code it spits out at the end into your Apache conf file.
Test whether Passenger has installed by running:
curl -sI localhost | grep ^Server
and check for the “Phusion_Passenger” signature. E.g.
Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Phusion_Passenger/4.0.5 mod_ssl/2.2.22 OpenSSL/0.9.8x
If you need to uninstall Passenger using sudo then:
$ sudo gem uninstall passenger
And a discussion on whether to use rvmsudo or not here:
https://groups.google.com/forum/#!topic/rubyversionmanager/9dnmAsTiHR4
In short, https://www.phusionpassenger.com/download
suggests using sudo
but the rvm page suggests not:
https://rvm.io/integration/passenger
Note:
If you get a warning doing the passenger install apache2 module like this:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
Warning: can not check /etc/sudoers
for secure_path
, falling back to call via /usr/bin/env
, this breaks rules from /etc/sudoers
. Run:
export rvmsudo_secure_path=1
Then run:
export rvmsudo_secure_path=1
and:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
(remember to run rvm requirements
afterwards)
On the Mac the Apache conf and restart commands go like this:
[~]$ sudo vim /etc/apache2/httpd.conf
[~]$ sudo apachectl restart
See also:
https://developer.apple.com/library/mac/#featuredarticles/PhusionRails/_index.html
The difference between .bash_profile and .bashrc?
It’s always slightly confusing to remember how these work on Linux, Unix and Mac OS X. According to the bash man page, .bash_profile gets run for every login shell (i.e. when you login) – put lengthy, one-off stuff there like the daily news
.bashrc gets run for every non-login shell (e.g. when you open up another terminal in your window system)
Unfortunately Mac OS X does things slightly differently – .bash_profile gets called for each new instance of a Terminal!
More:
http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
Assuming you’ve halted the runtime at the point where you invoked the Pry REPL (see Pry – Part 4), you should have the Pry REPL.
A. The main ways of navigating the stack are the ls and cd commands.
ls shows you methods, constants and variables.
cd moves you into the new context (object or scope).
1. ls
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
ls -h Usage: ls [-m|-M|-p|-pM] [-q|-v] [-c|-i] [Object] ls [-g] [-l] ls shows you which methods, constants and variables are accessible to Pry. By default it shows you the local variables defined in the current shell, and any public methods or instance variables defined on the current object. The colours used are configurable using Pry.config.ls.*_color, and the separator is Pry.config.ls.separator. Pry.config.ls.ceiling is used to hide methods defined higher up in the inheritance chain, this is by default set to [Object, Module, Class] so that methods defined on all Objects are omitted. The -v flag can be used to ignore this setting and show all methods, while the -q can be used to set the ceiling much lower and show only methods defined on the object or its direct class. -m, --methods Show public methods defined on the Object (default) -M, --instance-methods Show methods defined in a Module or Class -p, --ppp Show public, protected (in yellow) and private (in green) methods -q, --quiet Show only methods defined on object.singleton_class and object.class -v, --verbose Show methods and constants on all super-classes (ignores Pry.config.ls.ceiling) -g, --globals Show global variables, including those builtin to Ruby (in cyan) -l, --locals Show hash of local vars, sorted by descending size -c, --constants Show constants, highlighting classes (in blue), and exceptions (in purple). Constants that are pending autoload? are also shown (in yellow) -i, --ivars Show instance variables (in blue) and class variables (in bright blue) -G, --grep Filter output by regular expression -h, --help Show this message. |
2. cd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
> cd -h Usage: cd [OPTIONS] [--help] Move into new context (object or scope). As in UNIX shells use `cd ..` to go back, `cd /` to return to Pry top-level and `cd -` to toggle between last two scopes. Complex syntax (e.g `cd ../@x/y`) also supported. cd @x cd .. cd / cd - https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope -h, --help Show this message. |
B. Apart from navigating state, there are two other commands that are very useful, show-method and show-doc.
1. show-method
This shows the source for a method or class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
> show-method -h Usage: show-source [OPTIONS] [METH|CLASS] Aliases: $, show-method Show the source for a method or class. Tries instance methods first and then methods by default. show-source hi_method show-source hi_method show-source Pry#rep # source for Pry#rep method show-source Pry # for Pry class show-source Pry -a # for all Pry class definitions (all monkey patches) show-source Pry --super # for superclass of Pry (Object class) https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method -s, --super Select the 'super' method. Can be repeated to traverse the ancestors -l, --line-numbers Show line numbers -b, --base-one Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands) -a, --all Show all definitions and monkeypatches of the module/class -h, --help Show this message. |
2. show-doc shows the documentation by running the method comments through rdoc or yard
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
> show-method -h Usage: show-source [OPTIONS] [METH|CLASS] Aliases: $, show-method Show the source for a method or class. Tries instance methods first and then methods by default. show-source hi_method show-source hi_method show-source Pry#rep # source for Pry#rep method show-source Pry # for Pry class show-source Pry -a # for all Pry class definitions (all monkey patches) show-source Pry --super # for superclass of Pry (Object class) https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method -s, --super Select the 'super' method. Can be repeated to traverse the ancestors -l, --line-numbers Show line numbers -b, --base-one Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands) -a, --all Show all definitions and monkeypatches of the module/class -h, --help Show this message. |
More on using Pry.
Let’s play around with it a little using the Hello World gem (if you haven’t already installed it, use: gem install hello_world). Then, in pry:
1 |
require 'hello_world' |
Some useful commands:
1. ls:
ls shows you which methods, constants and variables are accessible to Pry. By
default it shows you the local variables defined in the current shell, and any
public methods or instance variables defined on the current object.
So we can list, class methods:
1 2 |
ls HelloWorld -M [] |
i.e. nothing.
Instance methods:
1 2 |
ls HelloWorld -m HelloWorld.methods: say_hello |
i.e. this method is available.
And this is the default, i.e.
1 2 |
ls HelloWorld HelloWorld.methods: say_hello |
e.g.:
1 2 3 |
HelloWorld.say_hello hello world => nil |
2. cd
cd moves you into a new context (object or scope). As in UNIX shells use cd .. to go
back, cd / to return to Pry top-level and cd – to toggle between last two
scopes.
So,
1 |
cd HelloWorld |
and now:
1 2 3 4 |
pry(HelloWorld):1> self => HelloWorld pry(HelloWorld):1> ls -m HelloWorld.methods: say_hello |
So, we can invoke it like this:
1 2 3 |
pry(HelloWorld):1> say_hello hello world => nil |
However, if we’re only interested in the output value and not the return value then we can use a semi-colon:
1 2 3 |
pry(HelloWorld):1> say_hello; hello world pry(HelloWorld):1> |
1 2 3 4 |
[23] pry(HelloWorld):1> gem-cd hello_world /Users/snowcrash/.rvm/gems/ruby-1.9.3-p327/gems/hello_world-0.0.2 [24] pry(HelloWorld):1> .pwd /Users/snowcrash/.rvm/gems/ruby-1.9.3-p327/gems/hello_world-0.0.2 |
More in Pry – Part 3.
Not quite as awesome as an automatic post categoriser but still pretty handy:
http://wordpress.org/extend/plugins/automatic-post-tagger/