Skip to content

Instantly share code, notes, and snippets.

@A35G
A35G / Check Link and Filter text
Created April 10, 2014 10:41
A function simple and quick for a dummy control on a text for the presence of any link. Useful for a first check on the body of an e-mail composed by a contact form
@A35G
A35G / Search and replace words with blacklist
Created May 20, 2014 14:46
Search and replace words (using random characters) contained in a text, using blacklists
<?php
// Text to filter and to censure
$text_to_check = "Lorem ipsum DOLOR Bullshit";
// List of words to censor
$blacklist_words = array("God", "em", "shit", "pig");
//$blacklist_words = "shit";
// Function used to generate a random string length as word to replace
@A35G
A35G / Search and replace words with blacklist - v2
Created May 22, 2014 13:47
Search and replace words (using random characters) contained in a text, using blacklists - Optimized version
<?php
/**
* Search and replace words with blacklist - v. 0.2
* ------------------------------------------------------------
* Optimized version - Thanks to my friend:
* Flavio 'darkjoker' Giobergia - https://github.com/darkjoker
* ------------------------------------------------------------
*
* The generation of random characters, has been eliminated, to make
@A35G
A35G / detect_library.js
Last active August 29, 2015 14:08
How to detect if an external library has loaded
window.create_widget = function() {
if (jQuery("#box-dynamic").length)
$('#box-dynamic').html("Oh Yes");
}
window.loadjQuery = function(url, success) {
var script = document.createElement('script');
@A35G
A35G / date_payments.php
Created November 6, 2014 11:55
Through a date given as input, it returns the same date or the first date to make a payment by a deadline. A check is performed on the specified date, to see if the same appears as Italian festivity.
<?php
// Check if var is a valid date
function validateDate($date, $format = 'Y-m-d H:i:s') {
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
@A35G
A35G / customErrorHandler.php
Created May 27, 2015 16:08
Custom Script to manage Error Log in PHP
<?php
function customErrorHandler($errno, $errstr, $errfile, $errline) {
if (!(error_reporting() & $errno))
return true;
switch ($errno) {
case E_USER_ERROR:
@A35G
A35G / Base_url.js
Last active September 3, 2015 11:15
Get the address of the website or web application
function getBaseURL() {
var url = location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));
if (baseURL.indexOf('http://localhost') != -1) {
var url = location.href;
var pathname = location.pathname;
var index1 = url.indexOf(pathname);
@A35G
A35G / convert_csv_to_vcf.php
Last active January 17, 2016 12:29
CSV to VCF - Convert file for import Contacts
<?php
$csv_file = __DIR__."/contacts.csv";
/**
* Structure of the CSV file
* "Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","
@A35G
A35G / easter_egg.js
Created January 21, 2016 23:51
Pieces of code useful for sketching an easter egg in a website or a web app. By entering a word or a sequence of characters / symbols / or other, it is possible to perform a function if the condition is true; In case of 5 second pause between typing and the other, the sequence is emptied.
var sequence = '';
var timeout;
var reset_s = function() {
sequence = '';
}
$(document).on("keypress", function(event) {
@A35G
A35G / check_push_token.php
Created September 21, 2017 20:26
Is your device's Token for Push Notifications valid yet? Check it out now!
<?php
class PushMessage {
private $url = 'https://fcm.googleapis.com/fcm/send';
private $serverApiKey = "";
private $devices = array();
function __construct($apiKeyIn){
$this->serverApiKey = $apiKeyIn;