Skip to content

Instantly share code, notes, and snippets.

View BrainFeeder's full-sized avatar

Robrecht Wellens BrainFeeder

View GitHub Profile
@BrainFeeder
BrainFeeder / CommaSeparatedList.php
Created January 4, 2017 11:57 — forked from gbrock/CommaSeparatedList.php
Joins an array of strings into a comma-separated string of readable output.
<?php
/**
* Joins an array of strings into a comma-separated string of readable output.
* Array ['John', 'Paul', 'George', 'Ringo'] becomes the string "John, Paul, George, and Ringo".
*
* @param array $items
* @param bool|true $oxfordComma
* @param string $conjunction
* @return string
@BrainFeeder
BrainFeeder / parties_import.sql
Created January 25, 2017 15:06 — forked from gbrock/parties_import.sql
MySQL setup of a simple Party Model-based address book.
#
# Basic Party Model implementation for MySQL.
# - Parties are either People or Organizations.
# - Party names are tracked separately, including first_used and last_used as dates.
# - Parties can have e-mails addresses, phone numbers, and physical addresses.
# - Parties can have Relationships with one another.
#
#
# Party Model: http://www.tdan.com/view-articles/5014/
# SO answer that helped me get started: http://stackoverflow.com/questions/5466163/same-data-from-different-entities-in-database-best-practice-phone-numbers-ex/5471265#5471265
-- phpMyAdmin SQL Dump
-- version 3.4.11.1deb2+deb7u1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 20, 2015 at 01:42 PM
-- Server version: 5.5.40
-- PHP Version: 5.4.36-0+deb7u3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
@BrainFeeder
BrainFeeder / dateCalc.php
Created February 6, 2017 10:47
Administrative way of adding and substracting months in PHP
<?php
// FUNCTION 1 (without leap check?)
//////////////////////////////////////
$date=new DateTime();
$date->setDate(2008,2,29);
function addMonths($date,$months){
$init=clone $date;
$modifier=$months.' months';
@BrainFeeder
BrainFeeder / Math.round.js
Created February 7, 2017 12:21
Rounding floats in JavaScript
// Closure
(function() {
/**
* Decimal adjustment of a number.
*
* @param {String} type The type of adjustment.
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
* @returns {Number} The adjusted value.
*/
@BrainFeeder
BrainFeeder / OpenSSL-and-WAMP.txt
Created February 28, 2017 10:31
How-to: self sign certificate with OpenSSL and WAMP
(
Tutorial found at https://fash7y.wordpress.com/2011/12/03/solved-how-to-set-up-https-with-openssl-in-wamp/
Tested with Apache 2.4.9 and got it working.
Note: http://stackoverflow.com/questions/16658038/cant-open-config-file-usr-local-ssl-openssl-cnf-on-windows
If error during creating key file.
)
@BrainFeeder
BrainFeeder / validatorRules.js
Last active March 22, 2017 08:40
String validation regex (used by cPanel)
var match_validators = {
fullemailaddress: eval("/^([a-zA-Z0-9_'+*$%^&!.-])+[@+](([a-zA-Z0-9-])+.)+([a-zA-Z0-9:]{2,4})+$/"),
emailcharplus: eval("/^([a-zA-Z0-9_'+.-])/"),
emailaddress: /^[^\@]\@[^\.]\./,
emailchars: /^[a-z0-9\_\-\@\.]+$/,
email_localpart_chars: /^\w[\w-.+%]*/,
email_localpart_chars_cap: /^[A-Za-z0-9\_\-\.]+$/,
atsign: /\@/,
notestsign: /\@/,
hostname: /^((\*\.|[a-zA-Z0-9])([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/,
@BrainFeeder
BrainFeeder / .htaccess
Created March 22, 2017 08:46
Force php version in .htaccess
AddHandler application/x-httpd-php53 .php
@BrainFeeder
BrainFeeder / regExVat.php
Created March 22, 2017 09:20
Function that uses regular expressions to match against the various VAT formats required across the EU
<?php
/**
* This is a function that uses regular expressions to match against the various VAT formats required across the EU.
* (tested, simple but effective)
*
* TODO: Change country names to ISO codes?
*
* @param integer $country Country name
* @param integer $vat_number VAT number to test e.g. GB123 4567 89
* @return integer -1 if country not included OR 1 if the VAT Num matches for the country OR 0 if no match
@BrainFeeder
BrainFeeder / dymoLabel.xml
Last active March 22, 2017 09:39
Example DYMO address label for use with the SDK
<?xml version="1.0" encoding="utf-8"?>
<DieCutLabel Version="8.0" Units="twips">
<PaperOrientation>Landscape</PaperOrientation>
<Id>Address</Id>
<PaperName>30252 Address</PaperName>
<DrawCommands>
<RoundRectangle X="0" Y="0" Width="1581" Height="5040" Rx="270" Ry="270" />
</DrawCommands>
<ObjectInfo>
<AddressObject>