Skip to content

Instantly share code, notes, and snippets.

View QROkes's full-sized avatar

Cristhian Martínez Ochoa QROkes

View GitHub Profile
@QROkes
QROkes / nginx.conf
Last active April 10, 2024 23:29
Nginx (Reverse Proxy) Configuration file for Traccar GPS
server {
listen 80;
listen [::]:80;
server_name domain.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@QROkes
QROkes / nginx.conf
Last active September 26, 2023 16:41
NGINX Configuration for WordPress Multisite + Domain Mapping with HTTPS
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com subsite.com www.subsite.com another.com www.another.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
@QROkes
QROkes / file.php
Created March 18, 2016 18:49
Get HTML source code with cUrl (file_get_contents as fallback)
$urlcontent = qr_loadUrl( 'http://myurl.com' );
function qr_loadUrl( $url ) {
if(is_callable( 'curl_init' )) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
@QROkes
QROkes / qa-plugin.php
Last active February 23, 2021 10:30
Anti SPAM Registration Plugin for Question2Answer - StopForumSpam API
<?php
/*
File: qa-plugin/webinoly-custom/qa-plugin.php
Description: Anti SPAM Registration Plugin for Question2Answer
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
@QROkes
QROkes / functions.php
Created March 25, 2016 02:57
Embed Gist - WordPress
<?php
// Embed gist without JavaScript in WordPress
wp_embed_register_handler( 'gist', '/https?:\/\/gist\.github\.com\/([a-z0-9\/]+)([\?\#]file[=-].*)?/i', 'qr_embed_gist' );
function qr_embed_gist( $matches, $attr, $url, $rawattr ) {
if(empty($matches[1])){$matches[1]=null;}
if(empty($matches[2])){$matches[2]=null;} // Query single file
$file = wp_remote_get( esc_url_raw( 'https://gist.github.com/' . esc_attr($matches[1]) . '.json' ) );
@QROkes
QROkes / mypage.html
Last active August 21, 2020 23:46
HTML Head metatags with OpenGraph (Facebook & Twitter)
<html lang="es-MX" xmlns:fb="http://ogp.me/ns/fb#" prefix="og: http://ogp.me/ns#"/>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Titulo de la página</title>
<meta name="description" content="Descripción de la página"/>
<link rel="canonical" href="http://mydomain.com/pagina" />
<meta name="robots" content="index,follow" />
@QROkes
QROkes / qa-plugin.php
Last active January 11, 2020 20:35
Akismet SPAM Check for Question2Answer
<?php
/*
File: qa-plugin/webinoly-custom/qa-plugin.php
Description: Anti SPAM Registration Plugin for Question2Answer
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@QROkes
QROkes / bash
Created April 7, 2019 21:58
Check if domain name is subdomain
# Check if domain is subdomain
if [[ -n $domain ]]; then
count=1
while true; do
tld=$(echo "${domain}" | rev | cut -d'.' -f -$count -s | rev)
if ! grep -Fxq "$tld" /opt/webinoly/lib/public_suffix_list.dat; then
break
fi
count=$[$count+1]
done
@QROkes
QROkes / bash
Created April 7, 2019 21:36
Check for valid domain name
# Only numerals 0-9, basic Latin letters, both lowercase and uppercase, hyphen.
[[ $domain =~ ^[\.0-9A-Za-z\-]+$ ]] || domfail="true"
# Check Lenght
[[ ${#domain} -gt 67 ]] && domfail="true"
# Can not start or end with a hyphen
[[ $(echo "${domain}" | cut -c-1) == "-" || $(echo "${domain}" | rev | cut -c-1) == "-" ]] && domfail="true"
# Can not contain two points together and can not start or end with a point
@QROkes
QROkes / bash
Created April 7, 2019 21:32
Check for valid IP address
# Check for valid IPv4 and IPv6 values, including CIDR.
if [[ -n $ip && $ip =~ ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/([0-9]|[1-2][0-9]|3[0-2]))?$ || $ip =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(\/([0-9]|[1-9][0-9]|1[0-2][0-8]))?$ ]]; then
echo "Valid IP!"
else
echo "[ERROR]