"foo_and_bars".classify
# => "FooAndBar" #String
"foo_and_bars".classify.constantize
# => "FooAndBar" #Class
# In Ruby, class names are constants, so you can do
str = "Thing" # => "Thing"
Kernel.const_get(str) # => Thing
class Person
def initialize(name)
@name = name
end
end
class Employee < Person
end
To copy code from the terminal use
- Cntrl + Insert
- Rightclick + copy text
To paste code into the terminal use
- Shift + Insert
- Rightclick + p
attr_accessor is used to create setter and getter methods for instance variables so that they can be accessed outside the class. initialize is the special method in ruby that gets called when an object is instantiated.
class Birthday
attr_accessor :name
def initialize age, gender
@age = age
self.gender = gender
To get formatted results for select statements use \G as a suffix for the query.
select * from table_name \G;
As we use object.class method in Ruby world, to check the class of a variable in Javascript, here is the snippet
var ss = "some string";
alert (typeof ss); #=> string
alert (typeof pp); #=> undefined
In case you have trouble in accessing internet using your wired connection and while troubleshooting, if your network manager says that
"device is not managed"
open the terminal and follow the below steps to fix the issue.
sudo vim /etc/NetworkManager/NetworkManager.conf
change the line managed=false to managed=true
To access remote machine using SSH
> ssh user@remote-host
> enter password when prompted
To get rid of entering password everytime you try to access, SSH keys has to be exchanged between local machine and remote server.
> ssh-keygen [Enter] [Enter] [Enter]
grep -rnw 'directory' -e "text-to-search"
-r is recursive, -n is line number and -w stands match the whole word.
grep --include={*.c,*.h} -rnw 'directory' -e "pattern"
gksudo nautilus
aletrnatively,
sudo nautilus