Skip to content

Instantly share code, notes, and snippets.

andybeak

Block or report user

Report or block andybeak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@andybeak
andybeak / logout.php
Last active Oct 21, 2019
Log out a user using server-side sessions
View logout.php
<?php
// can't log out if the session isn't started
session_start();
// emptying the session data is useful if your script continues running after logging out
$_SESSION = [];
// set the cookie to expire immediately
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
@andybeak
andybeak / nginx_tls.conf
Last active Sep 14, 2019
Nginx TLS config #book
View nginx_tls.conf
server {
listen 443 ssl;
server_name example.com;
ssl on;
// enable HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains;";
// prevent clickjacking
add_header X-Frame-Options "SAMEORIGIN";
@andybeak
andybeak / nginx.conf
Last active Aug 22, 2019
nginx cors allow origins #course #book
View nginx.conf
// See https://nginx.org/en/docs/http/ngx_http_map_module.html
// This sets the value of $cors_header depending on the value of $http_origin
map $http_origin $cors_header{
default "";
"~^(https:\/\/safedomain\.com)$" "$http_origin";
"~^(https:\/\/anotherdomain\.com)$" "$http_origin";
}
server {
listen 80;
View gist:3817d12fb94af49b3d6037c2f0eca134
<?php
// Answer from https://stackoverflow.com/questions/7648623/dynamically-running-clamavs-clamscan-on-file-uploads-with-php
$safe_path = escapeshellarg($_FILES['uploadedfile']['tmp_name']);
$command = 'clamscan ' . $safe_path;
$out = '';
$int = -1;
exec($command, $out, $int);
@andybeak
andybeak / docker-compose.yml
Created Mar 21, 2019
NomadPHP php speed comparison demo
View docker-compose.yml
version: '3'
services:
nginx:
image: nginx:1.13.1
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
@andybeak
andybeak / docker-compose.yml
Created Mar 14, 2019
Sonarqube in docker-compose with mysql
View docker-compose.yml
version: '3'
services:
sonarqube:
image: 'sonarqube:6.7.6-community'
restart: always
networks:
- sonarnet
ports:
- "10000:9000"
volumes:
View docker-compose.yml
version: '3'
services:
sonarqube:
image: 'sonarqube:6.7.6-community'
restart: always
networks:
- sonarnet
ports:
- "10000:9000"
volumes:
@andybeak
andybeak / delete_all_my_github_repositories.sh
Created Nov 4, 2018
Delete all your github repositories
View delete_all_my_github_repositories.sh
#!/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 Sep 29, 2018
LinkedIn article on Django and Azure
View access_token.py
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
View check_bash_script_dependencies.sh
#!/usr/bin/env bash
SCRIPT_DEPS="python terraform ssh-keygen ssh-add"
function die {
echo $1 >&2
exit 1
}
function missing_deps {
You can’t perform that action at this time.