Skip to content

Instantly share code, notes, and snippets.

@JenCant
JenCant / php.ini
Created March 31, 2021 16:16
[xdebug config] add these to php.ini to configure xdebug OR set them in php
#ini_set('xdebug.var_display_max_data', '2024');
xdebug.max_nesting_level=10000
xdebug.var_display_max_data=2024
@JenCant
JenCant / debian.sh
Created March 31, 2021 10:40
[debian linux snippets] #debian #linux #stretch #sources
# get the updated sources list for old debian / stretch
echo "deb http://ftp.debian.org/debian stretch-backports main" | tee /etc/apt/sources.list.d/backports.list
apt-get update
@JenCant
JenCant / app-engine-gcp-cloud-sql--timezones.php
Created March 10, 2021 13:14
app engine php + mysql timezone setting
/*-- MYSQL timezone conversion
DATE_ADD(CONVERT_TZ(NOW(), 'GMT', 'Europe/London'),INTERVAL 60 MINUTE)
CONVERT_TZ(NOW(), 'GMT', 'Europe/London')
*/
## test via php.ini timezone set in google app engine
echo date_default_timezone_get();
date_default_timezone_set('Europe/London');
@JenCant
JenCant / pprint-var_dump.py
Last active February 4, 2021 12:11
[python var_dump] Closest equivalent I've found #python #var_dump
from inspect import getmembers
from pprint import pprint
pprint(getmembers(yourObj))
# or...
pprint(vars(your_object))
@JenCant
JenCant / gcp-metadata-project-id.py
Last active January 28, 2021 14:39
[local cloud functions instrux] setup cloud function to test locally #gcp
# Get project ID dynamically -- will not work on local environment
import urllib.request
url = "http://metadata.google.internal/computeMetadata/v1/project/project-id"
req = urllib.request.Request(url)
req.add_header("Metadata-Flavor", "Google")
PROJECT_ID = urllib.request.urlopen(req).read().decode()
#neater version
import google.auth
@JenCant
JenCant / gc_secretmanager_python--call-once.py
Last active February 4, 2021 12:09
[gcloud access secrets in python] google's example for secretmanager in python #gcloud #gcp #secrets
import os
from google.cloud import secretmanager
# Get project ID dynamically -- will not work on local environment
# not set automatically in newer runtimes - python3.7 and other older runtimes used to have auto access.
import urllib.request
url = "http://metadata.google.internal/computeMetadata/v1/project/project-id"
req = urllib.request.Request(url)
req.add_header("Metadata-Flavor", "Google")
PROJECT_ID = urllib.request.urlopen(req).read().decode()
@JenCant
JenCant / gcp-create-secret.bash
Created January 25, 2021 11:16
[gcloud create new secret] creates a new secret named greeting, value = 'Hello' #gcp #gcloud
echo -n "Hello" | \
gcloud secrets create greeting \
--data-file=- --replication-policy=automatic
@JenCant
JenCant / gcp_secretmanager_example.py
Last active February 4, 2021 12:08
[GCP secretmanager] w/ python example #python #gcp #secrets
import os
from google.cloud import secretmanager
# init secret manager
client = secretmanager.SecretManagerServiceClient()
secret_name = "TEST_SECRET"
project_id = "861704209512"
request = {"name": f"projects/{project_id}/secrets/{secret_name}/versions/latest"}
response = client.access_secret_version(request)
secret_string = response.payload.data.decode("UTF-8")
// Ensure no caching takes place in browser
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.
if ("OPTIONS" === $_SERVER['REQUEST_METHOD']) {
/**
* This request type is purely for browser requests of type 'options'
* This is when a browser network request (i.e. fetch from cross site)
* runs a preflight 'check' to determine the allowed headers from this server.
@JenCant
JenCant / day1
Created December 2, 2020 09:53
the snippets from advent of code 2020 messy but working
public function test() {
$file = file_get_contents(FULL_PATH.'/httpdocs/input.txt');
$rawNumbers = explode(PHP_EOL, $file);
$count = count($rawNumbers);
echo "Total numbers to count: $count <br/>";
foreach ($rawNumbers as $key => $no) {
$no = (int) $no;
$neededNo = 2020 - $no;