Skip to content

Instantly share code, notes, and snippets.

@phpdave
phpdave / DB2 Commitment Control Isolation Level test.php
Last active August 29, 2015 14:14
Code to test out isolation level. While this program is running execute a SQL SELECT statement on the same table and see if you get less than 10,000 records at any point
<?php
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
for ($index = 0; $index < 10000; $index++)
{
$insertdata[] = array('test');
}
@phpdave
phpdave / IBM DB2 commitmentcontrol.php
Last active August 29, 2015 14:14
example of using commitment control in DB2. Not isolation levels don't appear to work.
<?PHP
//Add commitment control to the DB2 Connect by using i5_commit
//Apparently you can't set this using ini_set. Therefore this would have to be set in the PHP.ini
//ini_set('ibm_db2.i5_allow_commit',1);
ini_set('ibm_db2.autocommit',DB2_AUTOCOMMIT_OFF);
$options = array('i5_lib' => 'MYLIB','autocommit' => DB2_AUTOCOMMIT_OFF,'i5_commit' => DB2_I5_TXN_SERIALIZABLE);
//Connect to DB2 - Commitments wont take place until we call
//db2_commit($db2Connection) on the connection.
<?php
$server = db2_server_info( $db2Connection );
var_dump($server);exit();
//DFT_ISOLATION and ISOLATION_OPTION should be looked at
?>
@phpdave
phpdave / NetbeansReloadMozillaOnSave.ahk
Last active August 29, 2015 14:15
Simple script to refresh browser when you save a file in netbeans. You could modify the script to do even more advanced things if your proficient in AHK.
;Bind to CTRL+S key
~^S::
;If Netbeans is active (SunAwtFrame) is a class, you could change this to the actual title but you'll have to update the script more often
IfWinActive, ahk_class SunAwtFrame
{
;Msbox for debugging purposes. ; is used to comment it out
;MsgBox NetBeans Active
;Activate Firefox
@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 / subNavMenuByPageID.php
Created March 3, 2015 21:56
Get nav menu ID by "page id" and build sub navigation menu for that parent - WordPress PHP code
<?php
//this code is located in themes/{theme name}/page-templates/mypagetemplate.php in an area where i want to output the menu
//Get the Post/Page Id of the parent
if ($post->post_parent)
{
//go through post ancestors to find parent
$ancestors = get_post_ancestors($post->ID);
$parentPostId = $ancestors[count($ancestors) - 1];
}
@phpdave
phpdave / page.php
Created March 20, 2015 16:41
WordPress: Get current level navigation menu items and their children 1 level deep
<?php
//Get the Page Id of the parent
if ($post->post_parent)
{
//There's a parent post lets get the ancestors and grab the top
$ancestors = get_post_ancestors($post->ID);
$parentPostId = $ancestors[count($ancestors) - 1];
}
else
{
@phpdave
phpdave / GetColumnsAndNumberOfRows.sql
Last active August 29, 2015 14:18
get coulmns and record count in 1 SQL query
SELECT a.*, b.NumberOfRows
FROM MYTABLE a
CROSS JOIN (SELECT COUNT(*) AS NumberOfRows FROM MYTABLE) b
@phpdave
phpdave / unlinkTest.php
Created April 2, 2015 13:50
delete a file using unlink
<?php
if(unlink("test.txt"))
echo "true";
else
echo "false";
SELECT *
FROM MYTABLE
WHERE TRANSLATE (MYTABLE.MYFIELD, 'NNNNNNNNNNX', '1234567890N') = 'NNNNN' AND MYTABLE.MYFIELD<10000
--MYFIELD is a CHAR(5) field and is being compared against 5 'N's