Skip to content

Instantly share code, notes, and snippets.

View leowebguy's full-sized avatar

Leo Leoncio leowebguy

View GitHub Profile
@leowebguy
leowebguy / ValidateService.php
Created January 26, 2021 23:10
Craft 3 Entry Field Type Validation
<?php
/**
* Craft 3 Entry Validation
*
* This goes in the main plugin class.
*
* Event::on(
* Entry::class,
* Entry::EVENT_BEFORE_SAVE,
* function (ModelEvent $event) {
@leowebguy
leowebguy / iframe.js
Created February 18, 2020 15:23
pass utm parameters from url to iframe
if (window.location.search) {
const urlParams = new URLSearchParams(window.location.search);
var utms = [
"utm_medium=" + urlParams.get('utm_medium'),
"utm_source=" + urlParams.get('utm_source'),
"utm_campaign=" + urlParams.get('utm_campaign'),
"utm_content=" + urlParams.get('utm_content')
];
document.querySelectorAll('iframe')[0].src = document.querySelectorAll('iframe')[0].src + "&" + utms.join("&");
}
@leowebguy
leowebguy / block_badips.sh
Created May 30, 2017 18:13 — forked from Aikhjarto/block_badips.sh
Fetch a list of known brute force attackers from badips.com and apply/update iptables DROP rules
#!/bin/bash
# This script downloads a list of IPs known for brute force attacking within the last two weeks.
# The fetched IPs get blocked with iptables with the special comment "BADIP". This script only
# modifies iptables rules with that comment. This measure makes it well compatible with other firewall
# scripts like the SUSEFirewall.
# The iptables rules are updated every time this script is executed. Additionally this script is
# quiet on stdout, which makes it well suited for being executed as a cronjob.
#
# Please also use fail2ban with the badips modification and help to maintain the list of attackers.
# See also: fail2ban and http:///www.badips.com
html {
width: 100%;
overflow-x: hidden;
}
body {
width: 100%;
}
p {
margin: 0 0 20px 0;
}
@leowebguy
leowebguy / tick.js
Created July 13, 2016 13:51
Week Counter in JS+PHP
var EVENTDAY = '.esc_attr($day_number).'; // sunday
var EVENTHOUR = '.esc_attr($hour_number).'; // 9am
function getRemaining( now ) {
if ( now == null ) now = new Date();
var dow = now.getDay();
// the "hour" for now must include fractional parts of the hour, so...
var hour = now.getHours() + now.getMinutes()/60 + now.getSeconds()/3600;
@leowebguy
leowebguy / validation.js
Last active February 18, 2020 15:31
jquery validation (18+, february months, zip code...) + bootstrap dialog + ajax on submitHandler
function submitForm() {
$('form[name=registration]').submit();
};
function DialogThanks() {
BootstrapDialog.show({
title: '&nbsp;',
message: '<h1>Thank You</h1><p>You’re now enrolled. Thanks!</p>',
buttons: [{
label: 'Close',
@leowebguy
leowebguy / form.html
Last active July 12, 2016 17:12
jQuery Validation (18+, february months, zip code...) + Bootstrap Dialog + Ajax ... complete Form
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>jQuery Validation + Bootstrap Dialog + Ajax</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
@leowebguy
leowebguy / validation.js
Last active February 18, 2020 15:29
jquery validation (18+, february months, zip code...)
function submitForm() {
$('form[name=registration]').submit();
};
$("form[name=registration]").validate({
errorElement: "span",
errorClass: "has-error",
rules: {
dobMonth: {
required: true,
@leowebguy
leowebguy / validator.js
Last active February 18, 2020 15:28
jquery validade custom 18+
$.validator.addMethod('eighteenOrOlder', function(v, el) {
var month = $('input[name="dobMonth"]').val();
var day = $('input[name="dobDay"]').val();
var year = $('input[name="dobYear"]').val();
var birthDate = new Date();
birthDate.setFullYear(year, month - 1, day);
var currDate = new Date();
currDate.setFullYear(currDate.getFullYear() - 18);
if ((currDate - birthDate) > 0) {
return true;
@leowebguy
leowebguy / jquery_ajax.js
Last active February 18, 2020 15:26
jquery validate + ajax on submitHandler
function submitShare() {
$('form[name=share]').submit();
};
$("form[name=share]").validate({
submitHandler: function (form) {
var frm = $('[name=share]').serializeArray();
var data = {};
$.each(frm, function(i,v) {
data[v.name] = v.value