$ add-apt-repository ppa:pitti/postgresql
$ apt-get update
$ apt-get install postgresql libpq-dev
$ sudo -u postgres psql
postgres=# \password
Enter new password:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ User.all.each {|user| user.update_attributes(:active => true) } | |
| $ (1..100).each { InfoPack.find(246).sections.each { |s| s.sub_items.each { |si| si.update_attributes(:active => true) } } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| upstream unicorn { | |
| server unix:/tmp/unicorn.app1-web.sock fail_timeout=0; | |
| } | |
| server { | |
| listen 80 default deferred; | |
| # server_name example.com; | |
| root /home/deployer/apps/app1/current/public; | |
| # Maintenance state start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Postgresql database is running on server 192.168.0.1:5432 for user deployer | |
| # | |
| # Crearte SSH tunnel for pgadmin to connect to remote server. | |
| # localhost@5555 => 192.168.0.1@5432 | |
| # Connect using localhost & 5555 in PgAdmin | |
| $ ssh -fNg -L 5555:localhost:5432 deployer@192.168.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- http://stackoverflow.com/a/5408501 | |
| -- PostgreSQL 9.1 and below: | |
| SELECT pg_terminate_backend(pg_stat_activity.procpid) | |
| FROM pg_stat_activity | |
| WHERE pg_stat_activity.datname = 'TARGET_DB' | |
| AND procpid <> pg_backend_pid(); | |
| -- PostgreSQL 9.2 and above: |
Here's how to install PostgreSQL and have it run automatically at startup, on an Ubuntu 10.04 virtual machine using Vagrant. This took me a while to figure out:
Add the default lucid32 base box to your vagrant, if you haven't already:
host> vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
Now make a new lucid32 virtual machine and install postgresql on it:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ gem install rails | |
| Fetching: i18n-0.6.5.gem (100%) | |
| Successfully installed i18n-0.6.5 | |
| Fetching: multi_json-1.7.9.gem (100%) | |
| Successfully installed multi_json-1.7.9 | |
| Fetching: tzinfo-0.3.37.gem (100%) | |
| Successfully installed tzinfo-0.3.37 | |
| Fetching: atomic-1.1.13.gem (100%) | |
| Building native extensions. This could take a while... | |
| Successfully installed atomic-1.1.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl http://localhost:3000/api/v1/Action -H 'Authorization: Token token="api_key_goes_here"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Authenticate: | |
| curl -H 'Content-Type: application/json' \ | |
| -H 'Accept: application/json' \ | |
| -X POST http://localhost:3000/users/sign_in \ | |
| -d "{'user' : { 'email' : 'test@example.com', 'password' : 'password'}}" \ | |
| -c cookie | |
| # Show: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.factory "User", ["$http","$resource",($http,$resource) -> | |
| User = $resource("/roles/:id", {id: "@id"}, {update: {method: "PUT"}}) | |
| # Initialize the data using a static method | |
| User.init = (data) -> | |
| angular.extend this, data | |
| # a static method to retrieve User by ID | |
| User.get_it = (id) -> |