Skip to content

Instantly share code, notes, and snippets.

View mladoux's full-sized avatar

Mark LaDoux mladoux

View GitHub Profile
@mladoux
mladoux / botapi.php
Created August 30, 2020 07:22
takes data from pan-player-analytics/Plan and strips out unwanted elements for public presentation.
<?php
// API endpoint
$api = 'example.com/api_call';
// Parse uri segments
function uri(int $n)
{
$n++;
@mladoux
mladoux / gitea.sh
Last active February 17, 2020 05:35
Installs the latest version of gitea on a fresh ubuntu 18.04 server with an nginx front end. ( Needs to be run as root )
#!/bin/bash
# Download latest version of gitea
export LATEST=$(curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest | grep 'browser_download_url' | cut -d\" -f4 | grep 'linux-amd64' | grep -v .asc | grep -v .xz | grep -v .sha256)
wget -O gitea $LATEST
# Create user
echo "Creating git user"
adduser \
--system \
@mladoux
mladoux / clicheck.php
Created July 18, 2019 18:23
Check if PHP is being called via command line or web browser.
<?php
function CliCheck()
{
if (defined('STDIN')) return true;
if (php_sap_name() === 'cli') return true;
if (array_key_exists('SHELL', $_ENV)) return true;
if (
empty($_SERVER['REMOTE_ADDR']) &&
! isset($_SERVER['HTTP_USER_AGENT']) &&
@mladoux
mladoux / lso.sh
Created June 10, 2019 00:34
Simple awk script to convert permissions to octal ( good for learning octal permissions )
#!/bin/sh
ls -l | awk '{
k = 0
s = 0
for( i = 0; i <= 8; i++ )
{
k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
}
j = 4
@mladoux
mladoux / auth.php
Created March 27, 2019 18:14
Simple authentication class. Does not handle permissions or anything like that. Just something put together real quick and dirty.
<?php
/**
* Auth
*
* Verifies authentication credentials
*
* @author Mark LaDoux <mark.ladoux@gmail.com>
*/
class Auth
@mladoux
mladoux / ls-octal.sh
Created December 25, 2018 21:38
Get octal output from ls using awk
#!/bin/sh
ls -l | awk '{
k = 0
s = 0
for( i = 0; i <= 8; i++ )
{
k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
}
j = 4
@mladoux
mladoux / github-gist-monokai.css
Last active November 27, 2023 12:11
Monokai color scheme for gists ( with matching powered by github bar )
/* Monokai color Scheme Syntax Highlight Overrides ( REQUIRES 'body' TAGS TO WORK) */
body .gist .highlight {
background: #272822;
}
body .gist .blob-num,
body .gist .blob-code-inner,
body .gist .pl-s2,
body .gist .pl-stj {
color: #f8f8f2;
}
@mladoux
mladoux / github-gist-code-box.css
Last active February 3, 2022 12:02
Resize embedded gist code box and centers it. Adjust to taste.
/* Set width to 600px, and center box */
.gist {
margin-left: auto;
margin-right: auto;
width: 600px !important;
}
/* Limit height and width of script box, and enable scrollbars */
.gist-data {
height:250px;
@mladoux
mladoux / URI.php
Created December 25, 2018 20:13
URI Parser for DoomHamster Media Group ( Remove namespace from top of script if not using namespaces )
<?php namespace DHMedia\Input;
/**
* DHMedia URI Parser
*
* @author Mark LaDoux <mark.ladoux@gmail.com>
* @copyright Copyright © 2018, DoomHamster Media
* @license MIT <https://opensource.org/licenses/MIT>
*/
class URI
@mladoux
mladoux / routes.php
Last active November 23, 2018 17:40 — forked from geggleto/index.php
Slim 3 Middleware - Force HTTPS
// Enforce HTTPS
$app->add(function (Request $request, Response $response, $next) {
$cf = $this->get('settings');
// Check if configuration wants us to enforce https, so we can turn it
// on or off depending on whether the server supports https
if (isset($cf['force_https']) && $cf['force_https'] === true) {
if ($request->getUri()->getScheme() !== 'https') {
// Redirect to HTTPS