Skip to content

Instantly share code, notes, and snippets.

View fideloper's full-sized avatar
🏠
Working from home

Chris Fidao fideloper

🏠
Working from home
View GitHub Profile
@fideloper
fideloper / coverage.php
Created April 1, 2020 13:14
php coverage
#!/usr/bin/env php
<?php
// coverage-checker.php
$inputFile = $argv[1];
$percentage = min(100, max(0, (int) $argv[2]));
if (!file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}
@fideloper
fideloper / sqlite3.sh
Last active November 17, 2019 19:01
update sqlite on ubuntu 18.04 to version 2.30
#!/usr/bin/env bash
# Reference:
# https://stackoverflow.com/questions/9646353/how-to-find-sqlite-database-file-version
# Go to a known directory so we can cleanup files later
cd ~
# Download
wget https://www.sqlite.org/2019/sqlite-autoconf-3300100.tar.gz
@fideloper
fideloper / .zshrc
Created June 21, 2019 00:35
Defer loading of NVM to increase new terminal init speed
# Thanks to https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html, modified
# for zsh as "type -t" works in bash but not zsh
# Add this to your .zshrc ...
# Defer initialization of nvm until nvm, node or a node-dependent command is
# run. Ensure this block is only run once if .bashrc gets sourced multiple times
# by checking whether __init_nvm is a function.
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(type -w __init_nvm | awk '{print $2}')" = function ]; then
@fideloper
fideloper / connections.sh
Created December 19, 2018 19:48
Quick and dirty monitoring of mysql connections
#!/usr/bin/env bash
# 5 minutes between alerts
SECONDS_BETWEEN_ALERTS=300
# Track when we sent the last alert
LAST_ALERT=0
while true; do
NUMBER_CONNECTIONS=$(mysql --defaults-extra-file=/data/.prod.cnf -sNe "select count(*) as connection_count from INFORMATION_SCHEMA.PROCESSLIST;")
@fideloper
fideloper / transactions.md
Created March 17, 2018 18:27
write up on transactions

What we're demonstrating here is that it's probably smart to do most database operations in a transaction, even SELECT statements.

@fideloper
fideloper / tables.md
Last active August 21, 2017 13:33
delete me
Mac Linux Windows
Install Docker on Mac Install Docker on Debian Not Currently Supported
Install Docker on Ubuntu
Install Docker on CentOS
@fideloper
fideloper / stream_file.php
Last active January 17, 2024 18:41
Stream file from S3 to browser, assume Laravel Filesystem usage
<?php
/*************************************************************************
* Get File Information
*/
// Assuming these come from some data source in your app
$s3FileKey = 's3/key/path/to/file.ext';
$fileName = 'file.ext';
@fideloper
fideloper / start-container.sh
Last active August 31, 2021 10:59
Enable/Disable xDebug depending on env.
#!/usr/bin/env bash
###
# A CMD or ENTRYPOINT script for a Dockerfile to use to start a Nginx/PHP-FPM
#
# For more details, see 🐳 https://shippingdocker.com
##
if [ ! "production" == "$APP_ENV" ] && [ ! "prod" == "$APP_ENV" ]; then
# Enable xdebug
@fideloper
fideloper / convert_attach_from_db_to_file.php
Last active December 7, 2016 22:03
Converting Database Stored Attachments to the File System
<?php
/*
* Notes:
* This script will convert attachments from being stored on the DB to the file system
* NOTE: This script removes the atachments from your database. Before running this script make a backup. For real.
*/
//No time limit
set_time_limit(0);