Skip to content

Instantly share code, notes, and snippets.

View kgust's full-sized avatar

Kevin Gustavson kgust

  • Vanderbilt University Medical Center
  • Nashville, Tennessee USA
View GitHub Profile
@kgust
kgust / symfony-form-event-listener.php
Created March 31, 2024 02:20
This is an example Symfony form event listener.
<?php
$builder->addEventListener(FormEvents::POST_SUBMIT, function ($event) {
$form = $event->getForm();
$oldPassword = $form->get('old_password')->getData();
$newPassword = $form->get('password')->get('first')->getData();
$user = $this->security->getUser();
if (!$this->passwordEncoder->isPasswordValid($user, $oldPassword)) {
$form->get('old_password')->addError(new FormError('The old password is incorrect.'));
@kgust
kgust / fetch.js
Created March 31, 2024 02:16
Use JavaScript's native fetch
let promise = fetch(url, {
method: "GET", // POST, PUT, DELETE, etc.
headers: {
// the content type header value is usually auto-set
// depending on the request body
"Content-Type": "text/plain;charset=UTF-8"
},
body: undefined, // string, FormData, Blob, BufferSource, or URLSearchParams
referrer: "about:client", // or "" to send no Referer header,
// or an url from the current origin
@kgust
kgust / ldap.php
Created March 4, 2023 18:36
Testing LDAP Bind
<?php
// using ldap bind
$ldaprdn = $RDN; // ldap rdn or dn
$ldappass = $PASS; // associated password
// connect to ldap server
$ldapconn = ldap_connect($ldapUrl)
or die("Could not connect to LDAP server.");
<?php
// input misspelled word
$input = 'carrrot';
// array of words to check against
$words = array('apple','pineapple','banana','orange',
'radish','carrot','pea','bean','potato');
// no shortest distance found, yet
$shortest = -1;
@kgust
kgust / dark.md
Created December 4, 2018 18:01 — forked from a7madgamal/dark.md
Dark mode for Slack on MacOS
  1. Close slack
  2. Open this file /Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js
  3. Append this to it
document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css',
   success: function(css) {
 $("").appendTo('head').html(css);
@kgust
kgust / php-phpdbg-proxy.sh
Created November 29, 2018 13:39 — forked from VeryStrongFingers/php-phpdbg-proxy.sh
PHPStorm - PHP-PHPDBG Interpreter proxy
#!/bin/bash
#### Dirty/Fake PHP Interpreter to trick PHPStorm into using PHPDBG for running tests with/without code coverage
## For Mac/Linux only, Window's ubuntu subsystem theoretically would work too
##
##
## Related JetBrain's issues/feature requests
## https://youtrack.jetbrains.com/issue/WI-21414
## https://youtrack.jetbrains.com/issue/WI-29112
##
@kgust
kgust / 00 README.md
Last active August 29, 2018 20:18
All Things PlantUML

This is the best resource for PlantUML details.

Important Points

When you add the PlantUML plugin to PHPStorm, it creates a number of UML* template files that are examples that you can edit.

PlantUML can be generated by programs. E.g. php-plantumlwriter) It's even simple enough that we can write our own programs to generate PlantUML for our own use.

@kgust
kgust / docker-nginx-fastcgi.conf
Created August 15, 2018 02:18
A Nginx Configuration
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
@kgust
kgust / box.json.dist
Created August 15, 2018 02:15
Can we create a PHAR of our application using box?
{
"chmod": "0755",
"main": "app/console",
"output": "console.phar",
"directories": ["src"],
"finder": [
{
"name": "*.php",
"exclude": ["test", "tests", "Tests"],
@kgust
kgust / Caddyfile
Created August 15, 2018 02:14
Playing with Docker dynamic frontend servers
irbosx-c02q307.dhcp.mc.vanderbilt.edu:80 {
gzip
fastcgi / 127.0.0.1:9001 php {
root /app001/www/irb
index web/app_dev.php
}
}
localhost:8000 {
root /Users/gustavkd/github.com/vanderbilt/irb/web/