Skip to content

Instantly share code, notes, and snippets.

View mladoux's full-sized avatar

Mark LaDoux mladoux

View GitHub Profile
@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 / 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 <[email protected]>
*/
class Auth
@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 / 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 / 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 / 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++;