Skip to content

Instantly share code, notes, and snippets.

@graste
graste / rollyourown.php
Created May 8, 2020 13:10 — forked from GDmac/rollyourown.php
We don't need no DIC libs / we don't need no deps control
<?php
// Context: I'm trying to argue that DI (and DIC) are great, and DIC libs suck.
// Happy to be proven wrong!
final class Router {
private $dependencies;
public function __construct (Dependencies $dependencies) {
$this->dependencies = $dependencies;
// You might say that this is Service Locator, but it's not. This router is toplevel,
// and toplevel must have access to dependencies. After that it can all just bubble nicely using proper DI.
@graste
graste / psp.yml
Created March 18, 2020 16:23 — forked from abhisek/psp.yml
PodSecurityPolicy to Prevent hostPath Mount
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: developers-psp
spec:
privileged: false
allowPrivilegeEscalation: false
hostNetwork: false
hostPID: false
hostIPC: false
@graste
graste / test-php-basic-auth.php
Last active January 19, 2020 20:56 — forked from agwells/test-php-basic-auth.php
Ways to make a browser clear its cached HTTP basic auth credentials
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@graste
graste / random_user-agent.py
Created January 3, 2020 09:32 — forked from nickpopovich/random_user-agent.py
Script that goes with Python Scripter Burp Extension - every request passed through burp has a random User-Agent. Inspired by Marcin Wielgoszewski (@marcin) https://portswigger.net/bappstore/eb563ada801346e6bdb7a7d7c5c52583. Also inspired by Tim Tomes' (@lanmaster53) example scripts for Python Scripter https://gist.github.com/lanmaster53/3d86836…
import random
header_names = ['User-Agent']
ua = ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36', 'Mozilla/5.0 (Linux; Android 6.0; CAM-L21 Build/HUAWEICAM-L21; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36']
if (messageIsRequest):
request = helpers.analyzeRequest(messageInfo)
headers = request.getHeaders()
for header_name in header_names:
@graste
graste / Main.sc
Created November 17, 2019 19:02 — forked from tPl0ch/Main.sc
Message-Driven Finite-State-Transducer Domain-Driven-Design Aggregate
import cats.instances.either._
import Transducer.run
import UserRegistration._
object Main extends App {
private val commands = List(GDPRDeletion, StartRegistration, StartRegistration, ConfirmAccount, GDPRDeletion)
run(userRegistration)(commands).foreach(println)
// OUTPUT
library(osmplotr)
valpo <- get_bbox(c(-71.660, -33.065, -71.610, -33.015))
valpo_roads <- extract_osm_objects(key = 'highway', bbox = valpo)
map <- osm_basemap(valpo, bg = 'gray20')
map <- add_osm_objects(map, valpo_roads, col = 'gray70')
print_osm_map(map,
filename = './outputs/02-valparaiso-dark.jpg',
width = 2000, units = 'px', dpi = 300)
@graste
graste / def-sample.xml
Created August 22, 2019 21:58 — forked from mamund/def-sample.xml
ALPS document w/ various examples of the `def` element
<alps>
<doc>Sample Service</doc>
<!-- properties -->
<descriptor id="identifier" def="https://schema.org/identifier" />
<descriptor id="givenName def="https://schema.org/givenName" />
<descriptor id="familyName def="https://schema.org/familyName" />
<descriptor id="status" def="https://schema.org/status" />
<descriptor id="dateCreated" def="https://schema.org/dateCreated" />
<descriptor id="dateModified" def="https://schema.org/dateModified" />
@graste
graste / README.md
Created August 18, 2019 09:13 — forked from mnapoli/README.md
SAM templates vs Serverless templates

SAM template for a Bref HTTP application:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
    MyFunction:
        Type: AWS::Serverless::Function
        Properties:
@graste
graste / index.js
Created August 18, 2019 09:07 — forked from dhavaln/index.js
S3 Select query from NodeJS
const
AWS = require('aws-sdk'),
{ Readable } = require('readable-stream');
const s3 = new AWS.S3({
region: 'ap-northeast-2'
});
s3SelectQuery = (query) => {
return new Promise((resolve, reject) => {
#!/usr/bin/python2
# -*- encoding: utf-8 -*-
# implementation of the serial protocol used by
# AM03127 LED signs. Based on the document
# AM004 - 03128/03127 LED Display Board Communication
# Version 2.2, Date Aug. 13, 2005
# My LED board is a "Mc Crypt 590996 / 590998"
# LED Light Writing Board