Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
stevesohcot / php-function-sanitize.php
Created November 14, 2021 18:46
PHP SQL Injection Prevention - function to sanitize
<?php
function quote_smart($db_connection, $value) {
if( get_magic_quotes_gpc() )
$value = stripslashes( $value );
$value = mysqli_real_escape_string($db_connection, $value );
$value = strip_tags($value);
$value = htmlspecialchars($value);
$value = trim($value);
return $value;
@stevesohcot
stevesohcot / sqlserver-view-stored-procedures.sql
Created November 7, 2021 14:50
View Stored Procedures in MS SQL Server
-- SQL Server: query all stored procedures in all databases
DECLARE @sql varchar(1000)
select @sql = 'use ? select
[database name] = db_name()
,[schema name] = SCHEMA_NAME([schema_id])
,name [stored proc name]
,create_date [create date]
,modify_date [last modify date]
@stevesohcot
stevesohcot / ring-central-3-legged-log-in-engine.php
Created October 10, 2021 19:56
PHP Ring Central 3 Legged Auth Login - 2 of 2
<?php
require('vendor/autoload.php');
use RingCentral\SDK\Http\HttpException;
use RingCentral\SDK\Http\ApiResponse;
use RingCentral\SDK\SDK;
$rcsdk = new SDK(constant('RINGCENTRAL_CLIENT_ID'), constant('RINGCENTRAL_CLIENT_SECRET'), constant('RINGCENTRAL_SERVER_URL'));
$platform = $rcsdk->platform();
if (isset($_REQUEST['oauth2callback'])){
@stevesohcot
stevesohcot / ring-central-3-legged-log-in.php
Created October 10, 2021 19:55
PHP Ring Central 3 Legged Auth Login - 1 of 2
<?php
require('vendor/autoload.php');
use RingCentral\SDK\Http\HttpException;
use RingCentral\SDK\Http\ApiResponse;
use RingCentral\SDK\SDK;
$rcsdk = new SDK(constant('RINGCENTRAL_CLIENT_ID'), constant('RINGCENTRAL_CLIENT_SECRET'), constant('RINGCENTRAL_SERVER_URL'));
$platform = $rcsdk->platform();
@stevesohcot
stevesohcot / ring-central-2-legged-login.php
Created October 10, 2021 19:51
PHP Ring Central 2 Legged Auth Login
<?php
require "vendor/autoload.php";
$rcsdk = new RingCentral\SDK\SDK(constant('RINGCENTRAL_TWO_LEG_CLIENT_ID'), constant('RINGCENTRAL_TWO_LEG_CLIENT_SECRET'), constant('RINGCENTRAL_TWO_LEG_SERVER_URL'), constant('RINGCENTRAL_TWO_LEG_APP_NAME') );
$platform = $rcsdk->platform();
$platform->login(constant('RINGCENTRAL_TWO_LEG_USERNAME'), constant('RINGCENTRAL_TWO_LEG_EXT'), constant('RINGCENTRAL_TWO_LEG_PASSWORD'));
@stevesohcot
stevesohcot / planet-scale-data-node-js.js
Created September 17, 2021 17:41
Planet Scale data retrieval - Node.js on Windows
const express = require('express')
const app = express()
const port = 3000
const fs = require('fs');
const mysql = require('mysql');
app.get('/', (req, res) => {
res.send('Hello World!')
})
@stevesohcot
stevesohcot / planet-scale-connect-node-js.js
Created September 17, 2021 17:33
Planet Scale Connect with Node.js
const express = require('express')
const app = express()
const port = 3000
const fs = require('fs');
const mysql = require('mysql');
app.get('/', (req, res) => {
res.send('Hello World!')
})
@stevesohcot
stevesohcot / sql-cte.sql
Created August 23, 2021 21:27
SQL Common Table Expression (CTE) example
WITH EmployeeList
(employee_id, employee_name, manager_id, manager_name, employee_level)
AS (
SELECT
Boss.employee_id,
Boss.employee_name,
Boss.manager_id,
Boss.manager_name,
1 AS employee_level
FROM EmployeeRoster Boss
@stevesohcot
stevesohcot / import-spreadsheet-to-database.vba
Last active November 8, 2021 15:19
VBA - import spreadsheet to database
Const strDbConn As String = "server=myServerName;Database=myDatabaseName;Trusted_Connection=Yes;Driver={ODBC Driver 17 for SQL Server}"
Public Function ImportData(sheet As String)
Dim i As Long
Dim strSQL As String
Dim totalRows As Long
totalRows = HowManyRows(sheet)
strInsertHeader = GetInsertHeader()
@stevesohcot
stevesohcot / vba-remove-rows-with-zero.vba
Created July 31, 2021 04:03
VBA - Remove rows with zero
Function removeRowsWithValueOfZero()
' Sort on the values (Col N)
' when it comes time to delete, it'll be much faster!
Range("A1").Select
ActiveWorkbook.Worksheets("data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("data").Sort.SortFields.Add2 Key:=Range("N:N"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("data").Sort