Skip to content

Instantly share code, notes, and snippets.

@GiovanniK
GiovanniK / gist:8823425
Created February 5, 2014 13:18
Montessori college rooster
<?php
$url = 'http://beheer.e-poc.nl/onderwijs/plugins/montessori/website/rooster_groesbeek.php';
preg_match_all("/<tr>(.+)<\/tr>/siU", @file_get_contents($url), $matches);
preg_match_all("/<td colspan=\"5\" class=\"title\">(.+)<\/tr>/siU", @file_get_contents($url), $titles);
$titles_count = count($titles);
$changes = $matches[0];
$changes = str_replace ('<td colspan="5">&nbsp;</td>', '', $changes);
@GiovanniK
GiovanniK / gist:9250569
Created February 27, 2014 13:59
Simple captcha
<?php
session_start();
if (empty($_SESSION['captcha']))
{
$captcha = mt_rand(10000, 99999);
$_SESSION['captcha'] = $captcha;
}
else
{
@GiovanniK
GiovanniK / gist:10002378
Created April 6, 2014 06:57
Make Apache work the CPU
<?php
// make sure the trackback ping's URL links back to us
$handle = fopen($url, "r");
$tb_page = '';
while (!feof($handle)) {
$tb_page .= fread($handle, 8192);
}
fclose($handle);
$pos = strpos($tb_page, "http://imgur.com");
if ($pos === false) {
@GiovanniK
GiovanniK / gist:11378562
Created April 28, 2014 17:27
CSF firewall configuration (Directadmin)
###############################################################################
# SECTION:Initial Settings
###############################################################################
# Testing flag - enables a CRON job that clears iptables incase of
# configuration problems when you start csf. This should be enabled until you
# are sure that the firewall works - i.e. incase you get locked out of your
# server! Then do remember to set it to 0 and restart csf when you're sure
# everything is OK. Stopping csf will remove the line from /etc/crontab
#
# lfd will not start while this is enabled
$.ajax({
type: "POST",
url: "form.php",
data: $('#form').serialize(),
beforeSend: function() {
$('#form').append('<div class="alert alert-success save-message">Saving...</div>');
},
success: function(data) {
$('.save-message').remove();
}
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$('input').keyup(function() {
# First, Install Vagrant and Virtualbox then:
# Create new project directory
mkdir -p ~/Sites/newproject # Create new project directory
mk ~/Sites/newproject # Go into your new project directory
# Setup Vagrant
vagrant init
# Edit vagrant file box and box url to install Ubuntu, just like https://gist.github.com/fideloper/dab171a2aa646e86b782#file-vagrantfile-share-var-www-rb-L6-L8
# Edit Vagrantfile to create a static IP address, just like https://gist.github.com/fideloper/dab171a2aa646e86b782#file-vagrantfile-share-var-www-rb-L10
<?php
$data['var'] = urlencode($_POST['var']);
$ch = curl_init();
$url = 'API_URL';
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));
@GiovanniK
GiovanniK / gist:de0fdf9b08fcdd0b9f10
Created August 18, 2014 07:56
Sort array (descending or ascending)
public static function do_sort($a, $b) {
$date = $a->publishOn;
$date2 = $b->publishOn;
$aval = strtotime($date);
$bval = strtotime($date2);
if ($aval == $bval) {
return 0;
<?php
$dir = __DIR__ . '/..';
$keys = [
'mijnkey'
];
$lock = $dir . '/DEPLOY.LOCK';
if (!file_exists($lock)) {
if (isset($_GET['key']) && in_array($_GET['key'], $keys)) {