Skip to content

Instantly share code, notes, and snippets.

View hoasung01's full-sized avatar
🎯
Focusing

nguyenngochai hoasung01

🎯
Focusing
View GitHub Profile
@hoasung01
hoasung01 / apache
Last active November 4, 2016 03:54 — forked from felipelavinz/apache
Canonical redirects for Apache, lighttpd and nginx
## Canonical redirect for Apache
# BEGIN Canonical Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] ## will match any domain that's not our main domain
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>
# END Canonical Redirect
@hoasung01
hoasung01 / SOLID.markdown
Created November 1, 2016 07:19 — forked from emaraschio/SOLID.markdown
SOLID Principles with ruby examples

#SOLID Principles with ruby examples

##SRP - Single responsibility principle A class should have only a single responsibility.

Every class should have a single responsibility, and that responsibility should be entirely encapsulated. All its services should be narrowly aligned with that responsibility, this embrace the high cohesion.

##OCP - Open/closed principle Software entities should be open for extension, but closed for modification.

@hoasung01
hoasung01 / post_comment_chart.js.jsx
Created October 22, 2016 04:29
post-comment-chart
var PostsCommentsChart = React.createClass({
getInitialState: function() {
return {
data: [],
step: ""
};
},
handleChange: function(data) {
var self = this;
@hoasung01
hoasung01 / tab-avenue28
Created September 23, 2016 09:30
tab-avenue28-stuck-js-when-class-changed
.tab-content{:style => "margin-bottom: 80px"}
#summary.tab-pane.fade.in.active
.content-box
%h4.block-header
= t("labels.project.opportunity_summary")
.show-more-content
.short-content
= raw(@project.investment_sumary)
.show-more-gradient
.text-right.show-more-link Show more
@hoasung01
hoasung01 / contact-us.php
Last active September 16, 2016 03:43
mailerphp
<?php
require_once('./Mail-1.3.0/Mail.php');
echo '>>> vao diiiii >>>>';
if(isset($_POST['send'])):
echo '>>>>vao submit>>>>';
if(isset($_POST['g-recaptcha-response'])):
echo '>>>>vao check recaptcha >>>';
//your site secret key
$secret = 'xxx';
// information made available through the dataLayer is easily used in Google Tag Manager.
// GTM-XXXXXX has to be changed to the actual GTM-code as shown in the implementation document
dataLayer = [{
'pageTitle': 'page title variable', //example
'loggedIn': 'TRUE', //example
'CLV': '2249.50', //example (only use . seperator for cents)
'userID': 'AB12345678' //example
}];
<!-- Google Tag Manager -->
@hoasung01
hoasung01 / jquery-mousewheel-fix-on-firefox
Created July 19, 2016 08:52
fix jquery mousewheel work on firefox
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Horizontally Scrolling Site from CSS-Tricks</title>
<link rel="stylesheet" href="style.css">
@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