Skip to content

Instantly share code, notes, and snippets.

View nickpoulos's full-sized avatar

Nick Poulos nickpoulos

View GitHub Profile
### Keybase proof
I hereby claim:
* I am nickpoulos on github.
* I am nickpoulos (https://keybase.io/nickpoulos) on keybase.
* I have a public key ASD0uOGC1hFvUvgg67oWMe1iZWb0sLkY32qRPsVxAylmuAo
To claim this, I am signing this object:
@nickpoulos
nickpoulos / ntpup.sh
Created July 23, 2019 04:50
Bash NTP Update Script
#!/bin/bash
# Forces an ntp update
#
# Based on SO user Martin Schröder's answer to "How to force a clock update
# using ntp?": http://askubuntu.com/a/256004/41943
# Fail fast (set -e will bail at first error)
set -e
if [ "$EUID" -ne 0 ]; then
@nickpoulos
nickpoulos / install_swoole.sh
Created August 16, 2019 21:13
Install Swoole On Laravel Homestead
#!/bin/bash
ini_file=$(php -i | grep "Loaded Configuration File" | awk 'NR==1{print $5}')
php_version_output=$(php -v)
php_version=${php_version_output:4:3}
sudo pecl channel-update pecl.php.net
sudo pecl install swoole
sudo echo "extension=swoole.so" >> $ini_file
sudo service php$php_version-fpm reload
@nickpoulos
nickpoulos / laravel-exists-morph-validator
Last active September 6, 2019 03:53
Laravel Validator Extension For Morphable Relations (ex. An exists rule for multiple conditions)
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Validator;
Validator::extend('poly_exists', function ($attribute, $value, $parameters, $validator) {
// usage:
// 'commentable_id' => 'required|poly_exists:commentable_type
if (! $type = Arr:get($validator->getData(), $parameters[0], false)) {
return false;
@nickpoulos
nickpoulos / upload.js
Created November 26, 2019 15:38
ES2016 File Upload With Progress
sendFile(fileInput) {
let percentCompleted = 0;
let endpoint = '/store/uploads/here';
const config = {
'Content-Type': 'multipart/form-data',
onUploadProgress: function(progressEvent) {
percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
console.log(percentCompleted);
}
@nickpoulos
nickpoulos / concurrent-pool.php
Last active November 23, 2021 04:44 — forked from tonysm/concurrent-pool.php
[Concurrent Requests] Concurrent Pools Using Laravel #php #laravel
<?php
// 1. Register the routes
Route::get('test/{lorem}', function ($lorem) {
sleep(3);
return response()->json([
'message' => $lorem,
'token' => Str::random(),
]);
@nickpoulos
nickpoulos / prometheus-install.sh
Last active September 30, 2021 03:21
[Install Prometheus Ubuntu] Install Prometheus on a Clean Ubuntu Box #ubuntu #prometheus #bash
#!/bin/bash
# Install Prometheus
#
# Fail fast (set -e will bail at first error)
set -e
if [ "$EUID" -ne 0 ]; then
echo "ERROR: '$0' must be as root."
exit 1
@nickpoulos
nickpoulos / setup-ssl.sh
Created November 23, 2021 04:39
[Secure Ubuntu With LetsEncrypt SSL] Setup an Ubuntu box with a fresh certificate from LetsEncrypt #bash #ssl #letsencrypt #server
#Install Certbot and it’s Nginx plugin with apt
sudo apt install certbot python3-certbot-nginx
@nickpoulos
nickpoulos / k8s-delete-pods-by-keyword.sh
Created November 23, 2021 04:43
[K8s Delete Pods By Keyword] Delete any running K8s pods containing a keyword #k8s #bash
# kubectl get pods | grep MyServiceName | while read -r line; do $line | awk '{print $1}' | kubectl delete pod $1; done
function delpods() {
local keyword=$1
kubectl get pods | grep $keyword | while read -r line ; do
local containerName=$(awk -v var="$line" '{print $1}')
echo "Deleteing $containerName..."
kubectl delete pod $containerName
done
}