Skip to content

Instantly share code, notes, and snippets.

View BrainFeeder's full-sized avatar

Robrecht Wellens BrainFeeder

View GitHub Profile
@BrainFeeder
BrainFeeder / server.php
Last active March 29, 2018 13:39
Setting up websockets with Ratchet and React in php (TLS/WSS)
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$pusher = new Pusher; // Create a Pusher class that implements Ratchet\Wamp\WampServerInterface
// The loop
// Binding to 127.0.0.1 means the only client that can connect is itself.
// To accept remotes we should bind to 0.0.0.0
@BrainFeeder
BrainFeeder / index.php
Created December 21, 2017 12:18 — forked from facultymatt/index.php
Codeigniter subdomain routing index file. Support for admin dashboard.
<?php
date_default_timezone_set('America/New_York');
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
@BrainFeeder
BrainFeeder / httpd-vhosts.conf
Created March 31, 2017 09:17
Apache Virtual host example
Virtual host servername
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
@BrainFeeder
BrainFeeder / fileInput.html
Last active March 22, 2017 15:28
Way to use input[type=file] with Bootstrap
<html>
<head>
<!-- original author: Cory LaViska (@SEE https://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3) -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.btn-file {
position: relative;
@BrainFeeder
BrainFeeder / class.floodblocker.php
Created March 22, 2017 11:57
Class allowing to protect the scripts from flooding and to prevent automatic download of the site from single IP
<?php
// ----------------------------------------------------------------------------
//
// class.floodblocker.php - FloodBlocker class, ver.0.01 (April 15, 2005)
//
// Description:
// Class allowing to protect the scripts from flooding and to prevent
// automatic download of the site from single IP.
//
@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>
@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 / .htaccess
Created March 22, 2017 08:46
Force php version in .htaccess
AddHandler application/x-httpd-php53 .php
@BrainFeeder
BrainFeeder / csv_helper.php
Created March 22, 2017 08:41
A CSV helper for CodeIgniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------
/**
* CSV Helpers
* Inspiration from PHP Cookbook by David Sklar and Adam Trachtenberg
*
* @author Jérôme Jaglale
* @link http://maestric.com/en/doc/php/codeigniter_csv
@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}$/,