Skip to content

Instantly share code, notes, and snippets.

@phpdave
phpdave / CI CD Notes.MD
Last active April 25, 2024 22:23
How to Automate your deployments and move towards Continuous Integration and Continuous Deployment

I. Prepare and Understand

Set up Public Keys between your Deployment Machine and the Remote Machines to deploy to

  1. On your local machine generate a public key that will be exchanged with the remote servers you'll be deploying to. This will authorize your computer to connect and not require a password
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_abccompany -C "Comment to remember whos key"

also setup your ~/.ssh/config with this info to tie your key to which host

Host 192.168.1.5
    Port 22
<?php
$sql="SELECT
CAST(1 as smallint) as smallint,
CAST(2 as INTEGER) as INTEGER,
CAST(3 as BIGINT) as BIGINT,
CAST(4. as real) as real,
CAST(5.1 as FLOAT) as FLOAT,
CAST(6.1 as DOUBLE) as DOUBLE,
CAST(7.1 as DECIMAL) as DECIMAL,
CAST(8.1 as NUMERIC) as NUMERIC,
@phpdave
phpdave / DB2ErrorHandler.php
Last active January 25, 2024 22:41
A PHP error handler to dump out what happened on the #IBMi #DB2 before an error occured.
<?
//only output the error if we're in the development environment
$APPLICATION_ENV="dev";
//set error handler to the callback function defined later
set_error_handler("myErrorHandler");
//connect to db
$db2Connection = db2_connect( '', '' , '',array('i5_lib' => 'QSYS'));
if (!$db2Connection)
@phpdave
phpdave / Location of various PHP related fiels.md
Last active January 25, 2024 22:08
Zend Server 9.1 on IBM i PHP 7.1.3
@phpdave
phpdave / cspheader.php
Last active October 25, 2023 05:23
CSP Header for PHP or Apache or .htaccess - Content Security Protocol
<?
//CSP only works in modern browsers Chrome 25+, Firefox 23+, Safari 7+
$headerCSP = "Content-Security-Policy:".
"connect-src 'self' ;". // XMLHttpRequest (AJAX request), WebSocket or EventSource.
"default-src 'self';". // Default policy for loading html elements
"frame-ancestors 'self' ;". //allow parent framing - this one blocks click jacking and ui redress
"frame-src 'none';". // vaid sources for frames
"media-src 'self' *.example.com;". // vaid sources for media (audio and video html tags src)
"object-src 'none'; ". // valid object embed and applet tags src
"report-uri https://example.com/violationReportForCSP.php;". //A URL that will get raw json data in post that lets you know what was violated and blocked
@phpdave
phpdave / .aliases
Last active February 24, 2023 11:06
Files to put in your /home/USER/ directory on IBM i to enable cool things in Bash
# .aliases
# vim:syntax=shexit
# Reload bash aliases
alias reload="source ~/.bash_profile"
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
<?php
$xml = simplexml_load_file('jcrcmds.xml');
$outputdir='./results';
!file_exists($outputdir)?mkdir(outputdir, 0700):"";
foreach ($xml->mbr as $mbr)
{
$filename=$outputdir.'/'.trim($mbr['mbrname']).'.rpg';
$data=(string) $mbr->copysrc;
file_put_contents($filename,$data);
echo $filename.' created.'.PHP_EOL;
@phpdave
phpdave / ConvertAllMembersToStreamFiles.PGM
Last active February 16, 2020 01:46
IBMi convert file members to stream files for git 1) Create Physical File triggers on the libraries you want to monitor 2) Triggers run ConvertAllMembersToStreamFiles.PGM which runs 3) CopyMembersToStreamFiles.php which is a PHP script that runs through an array of file members to run through CPYTOSTMF
CALL PGM(QP2SHELL) PARM('/usr/local/zendsvr/bin/php-cli batchphp/CopyMembersToStreamFiles.php')
--Authority Collection - https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzarl/rzarlautcolstart.htm
--https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/cl/strautcol.htm
STRAUTCOL USRPRF(USER1) LIBINF(*ALL) OBJ(*ALL) OBJTYPE(*ALL) OMITLIB((MYLIB1))
--https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/cl/endautcol.htm
ENDAUTCOL USER(USER1)
--View Data collected
SELECT * FROM QSYS2.AUTHORITY_COLLECTION
@phpdave
phpdave / sigh.cls
Created May 20, 2019 19:12 — forked from tsalb/sigh.cls
Sanity check your org's CRUD
String DEBUG_TEMPLATE = 'C:[C] R:[R] U:[U] D:[D] MA:[MA] RA:[RA] | [PROFILE_NAME] | [OBJECT_NAME]';
String TRUE_TEMPLATE = '[X]'; // do not use space, horizontal char alignment will be off
String FALSE_TEMPLATE = '[_]'; // same
Integer PROFILE_NAME_MAX_LENGTH;
// Grab the max chars of each, so we can get an evenly formatted / spaced output later
List<Integer> nameLengths = new List<Integer>();
for (Profile profile : [SELECT Name FROM Profile]) {
nameLengths.add(profile.Name.length());
}