Skip to content

Instantly share code, notes, and snippets.

@andybeak
andybeak / make_user.sh
Last active January 20, 2017 16:38
Create a new user
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
if [ $# -eq 0 ]
then
echo "You have to supply the name of the user as a parameter"
@andybeak
andybeak / pull_logs.sh
Last active January 24, 2017 08:47
Backup AWS RDS binary files to AWS S3
#!/bin/bash
FILES="$(mysql -u database.user -pdatabase.password -h database.host -Bse 'show binary logs' | cut -f 1)"
for file in $FILES
do
if [ ! -f files/$file ]; then
logger "Trying to download new file: $file"
echo "Trying to download new file: $file"
mysqlbinlog \
@andybeak
andybeak / trait_visibility.php
Created January 12, 2017 11:09
Trait visibility
class Animal
{
use Cat, Dog {
Dog::wantWalkies as protected doggyWalk;
// this next line does not work
// Dog::wantWalkies as protected insteadof Cat;
Dog::wantWalkies instead of Cat;
Dog::wantWalkies as protected;
@andybeak
andybeak / trait_name_conflict_resolution.php
Created January 12, 2017 11:05
Trait name conflict resolution
<?php
trait Dog
{
public function wantWalkies()
{
echo "Yes please!";
}
}
@andybeak
andybeak / singleton_trait.php
Created January 12, 2017 11:02
Singleton trait
<?php
trait Singleton
{
private static $instance;
private function __construct() {}
public static function getInstance()
{
if (!(self::$instance instanceof self)) {
@andybeak
andybeak / setup_iptables.sh
Last active January 9, 2017 12:48
Set up iptables for a webserver
#!/bin/bash
logger Configuring iptables
# Flush existing rules
sudo iptables -F
# Allow SSH from Brightsource
sudo iptables -A INPUT -p tcp -s 31.221.84.114/32 --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT
@andybeak
andybeak / rss.php
Created October 3, 2016 13:29
Very simple zero feature rss read class
class RSS
{
const CACHE_FILENAME = 'feed.cache';
const CACHE_TTL = 60;
/**
* Public exposed function to read the feed, checks if the cache needs to be refreshed and if so reads from web,
* otherwise reads from the cache
@andybeak
andybeak / default
Created September 28, 2016 14:06
For book - nginx configuration to show php version setup
# This is a minimal example used to demonstrate swapping PHP versions
# It is not production ready and omits basic security checks.
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
@andybeak
andybeak / app.component.ts
Last active October 15, 2016 13:12
For Blog - Using systemjs to include the Phoenix javascript client into your Angular 2 app
import { Component, Inject } from '@angular/core';
import { PhoenixChannelService } from './app.phoenix_channels.service';
@Component({
selector: 'my-app',
templateUrl: 'templates/app.html',
providers: [PhoenixChannelService]
})
export class AppComponent {
@andybeak
andybeak / TestCase.php
Created August 30, 2016 15:41
Speedy phpunit test execution in Laravel
/**
* setupBeforeClass
* @static
* @access public
*/
public function setup()
{
parent::setUp();
Session::flush();