Skip to content

Instantly share code, notes, and snippets.

@andybeak
andybeak / delete_all_my_github_repositories.sh
Created November 4, 2018 14:25
Delete all your github repositories
#!/bin/bash
token="Get from Github"
# Gets a list of the repositories you own (not ones granted through organisation)
curl -H "Authorization: token ${token}" https://api.github.com/user/repos?affiliation=owner | grep git_url | sed -r 's/( "git_url": "git:\/\/github.com\/)//' | sed -r 's/.git",//' > url_list.txt
# Deletes all the repositories it found on the line before
while read r;do curl -XDELETE -H 'Authorization: token ${token}' "https://api.github.com/repos/$r ";done < url_list.txt
rm url_list.txt
@andybeak
andybeak / access_token.py
Last active September 29, 2018 21:06
LinkedIn article on Django and Azure
def get_access_token(self, request):
authorization_header = request.META['HTTP_AUTHORIZATION']
bearer, _, token = authorization_header.partition(' ')
if bearer != self.AUTH_TYPE_PREFIX:
raise ValueError('Invalid token')
return token
@andybeak
andybeak / check_bash_script_dependencies.sh
Created August 9, 2018 08:35
Bash - check dependencies
#!/usr/bin/env bash
SCRIPT_DEPS="python terraform ssh-keygen ssh-add"
function die {
echo $1 >&2
exit 1
}
function missing_deps {
@andybeak
andybeak / di_violation.php
Last active February 8, 2018 16:40
SOLID laravel examples #blog
<?php
namespace App\Domain\Employee;
// this introduces a source code dependency
use App\Domain\Employee\ScreenOutput;
class Employee
{
// this violates the dependency inversion principal because we depend on a concretion
@andybeak
andybeak / partner.php
Created August 14, 2017 10:22
Find the number in a list of integers that does not have a partner
<?php
$list = [1,2,3,4,5,2,3,4,5];
$total = 0;
foreach ($list as $cursor) {
// note this is the binary xor operator, not the logical xor
$total = $total ^ $cursor;
}
@andybeak
andybeak / Dockerfile
Last active July 17, 2017 16:37
Docker with Phalcon and Blackfire
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \
&& mv /tmp/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so
@andybeak
andybeak / header.php
Last active June 16, 2017 15:46
I set an ETag that is based on a static version number because the only time I would want to process the file is if the version changes.
<?php
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == sha1('version 1.0')) {
header('HTTP/1.1 304 Not Modified');
exit;
}
header('Cache-Control: max-age=604800, public');
header('ETag: ' . sha1('version 1.0') );
?>
@andybeak
andybeak / exception-inheritance.php
Created March 21, 2017 12:21
PHP Exception inheritance
<?php
class MyException extends Exception {}
try {
throw new MyException();
} catch (Exception $e) {
@andybeak
andybeak / database.php
Created January 23, 2017 15:55
SSL database connection
'project_ssl' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE_PROJECT'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
@andybeak
andybeak / Encryptable.php
Created January 23, 2017 11:51
Encryptable Trait for Laravel
<?php
/**
* This trait applies accessors and mutators to a model attributes if the config setting to encrypt data at rest is on
*/
namespace App\Lib\Domain\Models;
use Config;
use Crypt;