Skip to content

Instantly share code, notes, and snippets.

View DaveRandom's full-sized avatar

Chris Wright DaveRandom

View GitHub Profile
@DaveRandom
DaveRandom / rant.md
Last active February 2, 2024 16:18
Why you should not use relative paths when working with files in PHP

TL;DR do what the last section tells you to do

What is the difference between a relative path and an absolute path?

An absolute path is one which includes all path components from the root of the file system. It starts with a leading / on unix-like operating systems, or a drive letter on Windows.

Unix: /full/path/to/file.php

Windows C:\full\path\to\file.php

@DaveRandom
DaveRandom / Draytek Google Domains DDNS Dynamic DNS Config.md
Last active March 11, 2023 01:41
Draytek Google Domains DDNS Dynamic DNS Config

How to configure a Draytek router to update your dynamic DNS record with Google Domains

Draytek Dynamic DNS Configuration Page

  1. Choose the "WAN Interface" strategy to use when determining the IP address used when performing updates.
  2. In the "Service Provider" field, choose "User Defined". Additional configuration fields appear.
  3. In the "Provider Host" field, enter domains.google.com
  4. In the "Service API" field, enter /nic/update?myip=###IP###&hostname=your.hostname.here, replacing "your.hostname.here" with the fully qualified name of the record you wish to dynamically update.
  5. In the "Auth Type" field, choose "Basic" (this is the default).
  6. In the "Connection Type" field, choose "HTTPS".
@DaveRandom
DaveRandom / client.php
Last active September 9, 2021 19:58 — forked from ikariiin/server.php
<?php declare(strict_types = 1);
function send_data($socket, $data)
{
echo "Sending data {$data}\n";
fwrite($socket, $data);
$response = fread($socket, 1024);
echo "Got response: {$response}\n";
}
@DaveRandom
DaveRandom / Module.vbs
Created July 5, 2013 15:38
Module for repositioning windows in Access using Window API calls
Option Compare Database
Option Explicit
Private Type Point
x As Long
y As Long
End Type
Private Type Position
left As Long
@DaveRandom
DaveRandom / php-script.bat
Created April 8, 2020 23:22
Execute batch file as PHP script (one line shebang for PHP scripts on Windows)
@(<nul set /p=#! & type ^"%~f0^") | php -- %* & goto :eof
<?php declare(strict_types=1);
// script goes here
var_dump($argv);
<?php
//echo dirname(__FILE__);
$curl = curl_init('https://mydomain.com/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_CERTINFO, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_STDERR, fopen('php://output', 'w'));
@DaveRandom
DaveRandom / login.php
Created August 19, 2018 16:59 — forked from rahuldottech/login.php
PHP session management
<?php
require 'secsesh.php';
session_start();
if(/*credentials check out*/){
s_start();
}
header( 'Location: somePage.php' );
@DaveRandom
DaveRandom / config.php
Last active July 26, 2018 00:50
Push notification daemon example for @PeeHaa
<?php
$pidFile = __DIR__ . '/push-notify.pid';
$localSockAddr = __DIR__ . '/push-notify.sock'; // used for sending updates
$publicSockAddr = 'tcp://0.0.0.0:1337'; // bind address for push clients
$remoteSockAddr = 'tcp://127.0.0.1:1337'; // push client remote address for testing
@DaveRandom
DaveRandom / script.js
Last active June 6, 2018 09:36
Tweet icon for Jeeves in SO chat
// ==UserScript==
// @name Tweet icon for Jeeves in SO chat
// @namespace http://room11.org/
// @version 1.0
// @description @PeeHaa sucks
// @author @DaveRandom
// @match *://chat.stackoverflow.com/rooms/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
/**
* Modifications to perform (processed in order)
*
* @type {Function[]}
*/
const modifications = [
(text) => text.replace(/!+/g, '!'),