Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
stevesohcot / create-tables.sql
Last active June 4, 2024 18:09
MS SQL create tables given a schema
-- MS SQL Server 2016
-- Generate "create table" for each table within the schema
-- https://stevesohcot.medium.com/sql-to-generate-create-table-statements-for-all-tables-given-a-schema-in-ms-sql-server-046f7ffde9a6
SELECT
'CREATE TABLE ' + SCHEMA_NAME(t.schema_id) + '.' + t.name + ' (' +
STUFF ((
SELECT ', ' + c2.name + ' ' + type_name(c2.user_type_id) +
CASE
WHEN c2.is_nullable = 1 THEN 'NULL'
@stevesohcot
stevesohcot / controller-sign-up.php
Created November 27, 2023 01:37
Google recaptcha with PHP - sign up controller
<?php
if (array_key_exists('signUpAttempt', $_POST)) {
$captcha = isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : null;
// ultimately these could be constants in a "secrets" file
// aka stored as environment variables
#$captchaPublic = constant('CAPTCHA_PUBLIC');
#$captchaSecret = constant('CAPTCHA_SECRET');
@stevesohcot
stevesohcot / sign-up2.html
Created November 27, 2023 01:33
Google recaptcha with PHP - sign up form (v2)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Google reCAPTCHA Example</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
@stevesohcot
stevesohcot / sign-up1.html
Created November 27, 2023 01:31
Google recaptcha with PHP - sign up form
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Google reCAPTCHA Example</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
@stevesohcot
stevesohcot / excel-run-stored-procedure-single-function.vba
Created August 7, 2023 15:09
Excel run stored procedure single function
Private Function getInfoFromStoredProcedure()
Dim sheet As String
sheet = "Data"
Worksheets(sheet).Select
Range("A1").Select
Set rPrint = Worksheets(sheet).Range("A2")
@stevesohcot
stevesohcot / excel-run-stored-procedure.vba
Created August 7, 2023 14:26
Excel VBA call function for Stored Procedure
Public Sub getDataFromRecordset()
Dim sheet As String
sheet = "Data"
Worksheets(sheet).Select
Range("A1").Select
Set rPrint = Worksheets(sheet).Range("A2")
@stevesohcot
stevesohcot / excel-run-stored-procedure.vba
Created August 7, 2023 14:25
Run Stored Procedure in SQL Server from Excel
Private Function getInfoFromStoredProcedure() As ADODB.Recordset
On Error GoTo Error:
Dim adoCon As ADODB.Connection
Dim adoCmd As ADODB.Command
Dim rst As New ADODB.Recordset
Set adoCon = New ADODB.Connection
Set adoCmd = New ADODB.Command
@stevesohcot
stevesohcot / import-sql-server-to-excel-vba.vba
Created August 7, 2023 14:05
Import SQL Server to Excel with VBA
Public Function getDataFromRecordset()
Dim sheet As String
sheet = "Output"
Worksheets(sheet).Select
Range("A1").Select
Dim strSQL As String
strSQL = "SELECT TOP 10 * FROM table"
@stevesohcot
stevesohcot / validate-column-headers.vba
Last active June 19, 2023 14:54
Excel VBA - validate column headers
Const COL_FIRST_NAME = "A"
Const ROW_HEADER = "2"
Dim validation As Boolean
validation = validateColHeaders()
If validation = False Then
End
End If
@stevesohcot
stevesohcot / excel-stored-procedure.vba
Created April 10, 2023 14:18
Run Stored Procedure and get contents in Excel VBA
Const strDbConn As String = "server=server-goes-here;Database=db-goes-here;Trusted_Connection=Yes;Driver={ODBC Driver 17 for SQL Server}"
Private Function getInfoFromStoredProcedure() As ADODB.Recordset
On Error GoTo Error:
Dim adoCon As ADODB.Connection
Dim adoCmd As ADODB.Command
Dim rst As New ADODB.Recordset