Skip to content

Instantly share code, notes, and snippets.

View scottlingran's full-sized avatar

Scott Lingran scottlingran

  • Melbourne, Australia
View GitHub Profile
Start manually:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Stop manually:

$ pg_ctl -D /usr/local/var/postgres stop -s -m fast
@scottlingran
scottlingran / github.md
Last active December 12, 2015 02:39
Creating a Github repo from CLI
$ curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}'
$ git remote add origin [email protected]:USER/REPO.git
$ git push origin master
@scottlingran
scottlingran / gist:4130432
Created November 22, 2012 10:26
Enable YAML in Rails Console
YAML::ENGINE.yamler = 'syck'
@scottlingran
scottlingran / gist:3738141
Created September 17, 2012 15:52
Model queries
### find things in your table
Model.find_by_<key>(value) # Limits 1
Model.where(:key => value) # No limit, returns all
example = Model.find_by_<key>(key)
example.key = 'value' # this will return the key/value and update it
### find/create by
Model.find_or_create_by_<key>(key)
@scottlingran
scottlingran / Cool_stuff.rb
Created September 8, 2012 09:27
Rescuing/Retrying error messages
# Some cool stuff
begin
# code
rescue #error message
# code to what next
retry # if you want to run begin again
end
@scottlingran
scottlingran / Tips.md
Created September 8, 2012 09:26
Useful command lines
### create new column in database model
$ rails generate migration add_column_to_<modelname> <column>:<class>
$ rake db:migrate

### drop a table from the database
$ rails c
$ ActiveRecord::Base.connection.drop_table :your_table_name

### using heroku
@scottlingran
scottlingran / Startproject.md
Created August 27, 2012 09:26
Starting a new app in Rails
$ rails new <name> -T -d postgresql
# makes new project with no tests and postgresql database
@scottlingran
scottlingran / workbitch.md
Last active October 9, 2015 08:17
Creating a database in Rails
$ psql -U postgres

### CREATION w/o Password
$ createuser
# fill shit in
$ createdb <databasename>
$ psql -U postgres
$ alter user <username>;
# ALTER USER