Skip to content

Instantly share code, notes, and snippets.

View hoasung01's full-sized avatar
🎯
Focusing

nguyenngochai hoasung01

🎯
Focusing
View GitHub Profile
@hoasung01
hoasung01 / gist:9a7e428dece3084c77be8260bca6c57b
Created April 25, 2016 03:36
multiple controllers in one views
- mình có 2 controllers khác nhau: users_controller và contact_details_controller
- nhưng trong views/users/edit mình muốn thêm vào form new của contact_details thì hướng giải quyết ra sao nhỉ?
- mình có tham khảo một số cách làm thì dùng form_tag url_for đến controllers và action name của contact_details_controller
- nhưng hiện tại thì mình đã implement các action name cho mỗi controller xong hết rồi
- sample code của mình:
```
class UserController < UserDashboardController
include Devise::Controllers::Helpers
include ContactDetailHelper
before_action :authorize_resource
@hoasung01
hoasung01 / README.md
Created March 7, 2016 02:15 — forked from derwiki/README.md
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

@hoasung01
hoasung01 / raspi_button_led.rb
Created January 21, 2016 10:16
raspi_button_led.rb
require 'artoo'
connection :arduino, :adaptor => :firmata, :port => '/dev/ttyACM0'
device :led, :driver => :led, :pin => 13
device :button, :driver => :button, :pin => 2
work do
on button, :push => proc {led.toggle}
end
@hoasung01
hoasung01 / factorygirl_basic_config.rb
Created January 14, 2016 03:22
factorygirl_basic_config.rb
http://willschenk.com/setting-up-testing/
@hoasung01
hoasung01 / add-more-remote-origin-repo.rb
Created January 11, 2016 12:58
add-more-remote-origin-repo
http://blog.schwuk.com/2013/02/11/using-multiple-remote-repositories-with-git/
@hoasung01
hoasung01 / postgres-could-not-connect-to-server.rb
Created December 29, 2015 14:46
postgres-could-not-connect-to-server
http://stackoverflow.com/questions/13410686/postgres-could-not-connect-to-server
@hoasung01
hoasung01 / reactjs-sublime-plugin.rb
Created December 24, 2015 06:48
[ReactJs-sublimeText]
http://www.nitinh.com/2015/02/setting-sublime-text-react-jsx-development/
@hoasung01
hoasung01 / RPi_Easy_SD_Card_Setup
Created November 27, 2015 19:33
RPi_Easy_SD_Card_Setup
http://elinux.org/RPi_Easy_SD_Card_Setup
@hoasung01
hoasung01 / install-sd-card-formatter.rb
Created November 27, 2015 19:29
install sd card formatter on Mac
https://www.sdcard.org/downloads/formatter_4/eula_mac/
@hoasung01
hoasung01 / loi-PG::ConnectionBad
Created November 27, 2015 01:42
PG::ConnectionBad - could not connect to server: Connection refused
It could be as simple as a stale PID file. It could be failing silently because your computer didn't complete the shutdown process completely which means postgres didn't delete the PID (process id) file. The PID file is used by postgres to make sure only one instance of the server is running at a time. So when it goes to start again, it fails because there is already a PID file which tells postgres that another instance of the server was started (even though it isn't running, it just didn't get to shutdown and delete the PID).
To fix it remove/rename the PID file. Find the postgres data directory. On a MAC using homebrew it is /usr/local/var/postgres/, other systems it might be /usr/var/postgres/.
To make sure this is the problem, look at the log file (server.log). On the last lines you will see: FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
If so, rm postmaster.pid
Restart your server. On a mac using launchctl (w