Skip to content

Instantly share code, notes, and snippets.

View enderandpeter's full-sized avatar
😃
All is well

Spencer Williams enderandpeter

😃
All is well
View GitHub Profile
@enderandpeter
enderandpeter / eks-iam.ps1
Last active April 29, 2020 13:43
Udacity FSND EKS Cluster and IAM Role Creation with Powershell
eksctl create cluster --name simple-jwt-api
$env:ACCOUNT_ID = aws sts get-caller-identity --query Account --output text
$env:TRUST = "{ \`"Version\`": \`"2012-10-17\`", \`"Statement\`": [ { \`"Effect\`": \`"Allow\`", \`"Principal\`": { \`"AWS\`": \`"arn:aws:iam::${env:ACCOUNT_ID}:root\`" }, \`"Action\`": \`"sts:AssumeRole\`" } ] }"
aws iam create-role --role-name UdacityFlaskDeployCBKubectlRole --assume-role-policy-document "$env:TRUST" --output text --query 'Role.Arn'
echo '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "eks:Describe*", "ssm:GetParameters" ], "Resource": "*" } ] }' > $env:temp\iam-role-policy
@enderandpeter
enderandpeter / extract-files.sh
Created November 1, 2016 23:12
An experimental script for using archiving programs to extract contents into uniquely named files
#!/bin/bash
# This script's use is largely overshadowed by 7-zip
# 7z e Archives*.zip -aot -o"Destination Folder" # Rename duplicate filenames
# 7z e Archives*.zip -aoa -o"Destination Folder" # Overwrite duplicate filenames
# 7z e Archives*.zip -aos -o"Destination Folder" # Skip duplicate filenames
# It should be possible to use `7z e Archives*.zip -aos -o"Destination Folder" *.* -r` to avoid
# extracting empty directories, but any such filter, such as *.* or even *, results in no files extracted on Windows.
filecount=0
@enderandpeter
enderandpeter / update_my_biz_trans_regex.php
Last active September 26, 2016 23:12
A spirited but perhaps ultimately futile attempt to programmatically extract the street name, number, and direction from thousands of non-standardized addresses, using one as an example, that were entered into the Murney Business Dashboard.
$subject = 'LOT 3 PHS 2 S OZ NATURAL FALLS DR';
$directionals = array('north', 'east', 'south', 'west');
$pattern = "/(?P<number>^(?:(?:L(?:ot)?|PHS\w*)?(?:\d+(?:th)?(?:\s*\(\d+\))?)?(?:[[:^alnum:]]+)?(?:L(?:ot)?|PHS\w*)?(?:\d+(?:th)?(?:\s*\(\d+\))?)?)+)\s+(?P<direction>north|east|south|west|n|e|s|w)?(?P<street>.*)/i";
$result = preg_match($pattern, $subject, $matches);
if($result === 1){
$matches_found = true;
} else if ($result === 0) {
@enderandpeter
enderandpeter / httpd.conf
Last active October 20, 2015 18:53
Recommended vhost configuration for Magento sites. All web users are granted access, except to the app folder which contains framework configuration. AllowOverride should grant only enough access as is required, so edit that line as necessary.
<VirtualHost *:80>
ServerName magento.local
DocumentRoot /var/www/magento
<Directory /var/www/magento>
Require all granted
AllowOverride FileInfo Indexes Options Limit
</Directory>
</VirtualHost>
@enderandpeter
enderandpeter / linebreaksplit.php
Last active January 2, 2016 20:29
Split on linebreaks and a delimiter on each line.
<?php
$thestring =<<< EOS
The beats: fast
The rhymes: bold
The brass: monkey
EOS;
// If this doesn't work, try the pattern /$\R?^/m
// Yes, that's the endline before the startline.
foreach(preg_split("/\r\n|\n|\r/", $thestring) as $line){
@enderandpeter
enderandpeter / file_put_contents_test.php
Last active December 30, 2015 03:49
Show the php process owner and the permissions for the current directory. Then try to write a file with file_put_contents.
<?php
$processUser = posix_getpwuid(posix_geteuid());
print 'Process owner: ' . '<b style="color:blue">' . $processUser['name'] . '</b>';
echo "<br /> This directory's permisions: <i>" . exec('ls -ld') . '</i><br />';
echo file_put_contents('test.txt', 'hey there') . ' bytes written.';
?>
@enderandpeter
enderandpeter / contentattributes.php
Last active June 17, 2020 19:01
Using PHP's SimpleXML class to find the attributes of a <media:content> element in an MRSS file.
<?php
$mrss =<<<EOS
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">
<channel>
<title>My Movie Review Site</title>
<link>http://www.foo.com</link>
<description>I review movies.</description>