Skip to content

Instantly share code, notes, and snippets.

View davebarnwell's full-sized avatar

Dave Barnwell davebarnwell

View GitHub Profile
@davebarnwell
davebarnwell / php_copy_to_paste_board.php
Last active July 30, 2017 16:33
PHP to copy a string to the mac os x paste board
<?php
function copy2clipboard($string){
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "a.txt", "a") // stderr is a file to write to
);
$process = proc_open('pbcopy', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $string);
@davebarnwell
davebarnwell / disc-inode.md
Last active July 24, 2017 07:11
Commands to help track down disk i-node usage

Show i-node usage by volume (-h = human readable)

dh -ih

Show total number of files below each directory from the current path, you can use this command to walk the filesystem, finding the directory with most files, then cd into it, repeat, and you should slowly decsend to find the directory with the large files creations in.

find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
@davebarnwell
davebarnwell / syn_docker_mac_clock_on_wake.sh
Created July 13, 2017 08:54
Sync the docker for Mac clock on wake from sleep
brew install sleepwatcher
brew services start sleepwatcher
echo /usr/local/bin/docker run --rm --privileged *OS-NAME* hwclock -s > ~/.wakeup
chmod +x ~/.wakeup
@davebarnwell
davebarnwell / propsOfTable.php
Last active July 7, 2017 09:36
generate PHP docblock @properties from a mysql table, great when using magic setters and getters
#!/usr/bin/env php
<?php
/**
* Generate PHP Doc blocks @property values for a given table
* helps when a class wraps a table and the class uses magic setters and getters
*
* Usage:-
* ./propsOfTable.php {mysqlTableName}
*/
@davebarnwell
davebarnwell / delete-empty-directories-in-sub-tree.md
Last active June 24, 2017 18:09
zero byte files, find, list, remove

delete all empty directories in a directory sub-stree

find . -type d -empty -delete
@davebarnwell
davebarnwell / bash-online_liners.md
Last active May 24, 2017 09:30
Bash find and delete file one liners

find all files not modified for 10 or more days

find /root/backups/EniscopeHub-*.sql.gz -mtime +10 -type f

delete all matching files not modified for 10 or more days

find /root/backups/EniscopeHub-*.sql.gz -mtime +10 -type f --delete

@davebarnwell
davebarnwell / encrpt_decrypt_openssl.sh
Created May 23, 2017 10:12
Encrypt and decrypt a file using openssl on the command line
#!/usr/bin/env bash
# Will prompt for a password to use as the shared secret
openssl enc -aes-256-cbc -in plain.txt -out encrpyted.dat
# Send encrpyted.dat to the recipient and communicate the secret password via another means
# To decrypt run the folowing which will prompt to enter shared secret password
openssl enc -aes-256-cbc -d -in encrpyted.dat >decrypted-plain.txt
@davebarnwell
davebarnwell / secure-ubuntu.sh
Created May 14, 2017 09:04
Script to secure ubuntu (the basics only)
#!/bin/bash
set -o errexit
# Disclaimer: This is not the most secure configuration possible. This script
# is only intended to be more secure than the default configuration. No
# promises are made about this script preventing your server from getting
# owned or your bike getting stolen. The bad guys are still out to get you.
# And running this script does not excuse you from writing secure application
# code!
@davebarnwell
davebarnwell / dumprequest.php
Created April 5, 2017 14:41 — forked from magnetikonline/dumprequest.php
PHP script to dump full HTTP request to file (method/HTTP headers and request body).
<?php
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
class DumpHTTPRequestToFile {
public function execute($targetFile) {
$data = sprintf(
"%s %s %s\n\nHTTP headers:\n",
$_SERVER['REQUEST_METHOD'],
@davebarnwell
davebarnwell / generateSSL
Created March 20, 2017 13:52
Generate a self signed SSL key pair for development
#!/usr/bin/env bash
#
# generate a self-signed SSL key pair
#
DOMAIN=dev.local
cat > openssl.cnf <<-EOF
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no