Instantly share code, notes, and snippets.

View enable-gzip-nginx.htaccess
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;
View enable-gzip-apache.htaccess
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
View woocommerce-cart-checkout-style.css
.woocommerce .col2-set .col-1, .woocommerce-page .col2-set .col-1, .woocommerce .col2-set .col-2, .woocommerce-page .col2-set .col-2 {
flex: 0 0 100%;
max-width: 100%;
}
/* Woocommerce Styles */
/*
A couple things to note...
1. This code was written very specifically for my base child theme so it might not work out of the box with every theme.
View remove-category-or-custom-taxonomy-slugs-from-url.php
<?php
/**
* Change Term Request.
*/
function pdvn_change_term_request( $query ) {
$tax_name = 'product_cat'; // specify you taxonomy name here, it can be also 'category' or 'post_tag'
// Request for child terms differs, we should make an additional check
if ( $query['attachment'] ) :
View remove-custom-post-type-slug-from-url.php
<?php
/**
* Remove custom post type slug from URL.
*/
function pdvn_remove_slug( $post_link, $post, $leavename ) {
if ( 'product' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
View elementor-control.php
<?php
/**
* TEXT control.
*/
$this->add_control(
'title',
[
'label' => __( 'Title', 'elementor' ),
'type' => Controls_Manager::TEXT,
'dynamic' => [
View text.html
<div class="ncn_form-control">[text* your-name placeholder "Họ và Tên"]</div>
<div class="ncn_form-control">[email* your-email placeholder "Email của bạn"]</div>
<div class="ncn_form-control">[tel your-phone placeholder "Số điện thoại"]</div>
<div class="ncn_form-control">[textarea your-message placeholder "Điền nội dung bạn muốn gửi..."]</div>
<div class="ncn_form-submit">[submit "Gửi đi"]</div>
View ex
> IRB
2.2.0: 001> require './math'
=> Đúng
2.2.0: 002> multiply_by_two 2
=> 4
2.2.0: 003> multiply_by_two -2
=> -4
2.2.0: 004> multiply_by_two
ArgumentError: Xin cung cấp một số hợp lệ
from /Users/bill/dev/math.rb:3:in 'multiply_by_two'
View ex
def multiply_by_two (n = "không có giá trị cung cấp")
if (n.is_a? (Integer))
n * 2
khác
nâng ArgumentError.new ( "Xin vui lòng cung cấp một số hợp lệ")
View ex
2.2.0: 004> multiply_by_two
ArgumentError: sai số của đối số (0 trong 1)
from /Users/bill/dev/math.rb:1:in 'multiply_by_two'
from (IRB): 4 từ /Users/bill/.rvm/rubies/ruby-2.2.0/bin/irb:11:in `main'
2.2.0: 005> multiply_by_two "ruby"
=> "Rubyruby"
2.2.0: 006> multiply_by_two nil
NoMethodError: Phương pháp xác định `* 'cho con số không: NilClass
from /Users/bill/dev/math.rb:2:in 'multiply_by_two'
from (IRB): 6