Skip to content

Instantly share code, notes, and snippets.

@roe3p
roe3p / datetimes.js
Created March 1, 2016 15:08
Javascript Datetime functions
/*DATETIME FUNCTIONS
Functions to create datetime strings in a specific format.
Created to force dates to be passed as SQL parameters in the correct format (i.e. not MM/DD/YYYY)
*/
function fDate(date) {
//Format date to 'dd/MM/yyyy'
if (typeof date == 'undefined') date = new Date();
@roe3p
roe3p / Fileexists.sql
Last active March 1, 2016 15:12
T-SQL function to check whether a file exists
-- =============================================
-- Author: Rohan Shenoy
-- Create date: 2013-10-28
-- Description: Function to return whether file exists
-- =============================================
CREATE FUNCTION [dbo].[fnFileExists] (@path varchar(512)) RETURNS BIT
AS
BEGIN
@roe3p
roe3p / pGetJSONFromTable.sql
Last active March 1, 2016 15:23
T-SQL to return contents of a table as a JSON object
//Gets all records in a SQL table and returns it as a single-dimension JSON object.
//If the parameter @VarName is passed, the returned output assignes the object to that variable.
CREATE PROCEDURE [dbo].[pGetJSONFromTable] @ObjectName VARCHAR(255), @VarName VARCHAR(255) = NULL, @registries_per_request smallint = null
AS
BEGIN
IF OBJECT_ID(@ObjectName) IS NULL
@roe3p
roe3p / pGetJSONfromQuery.sql
Created March 1, 2016 15:30
T-SQL procedure to get a JSON object based on the resultset of a SQL query
//Gets the result of the query @ParameterSQL and returns it as a single-dimension JSON object
//If variable @VarName is passed, the resultant output assigns the object to that variable
CREATE PROCEDURE [dbo].[pGetJSONFromQuery] @ParameterSQL NVARCHAR(4000), @VarName VARCHAR(255) = NULL
AS
BEGIN
DECLARE @SQL NVARCHAR(1000)
DECLARE @XMLString VARCHAR(MAX)
DECLARE @XML XML;
@roe3p
roe3p / 0_reuse_code.js
Created March 1, 2016 15:36
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@roe3p
roe3p / autoclose.vb
Created March 1, 2016 15:51
Excel VBA - Auto-close routines
'These routines will auto-close a workbook after a period of inactivity, useful for centrally-accessed
'non-shared workbooks that need to be accessed by multiple people. Also optional indicator to show who has
'opened the file, in case Excel only shows 'another user.'
'Put the following code in the 'ThisWorkbook' module:
'Timeout in seconds
Const Timeout As Integer = 300
'Flag to enable auto-close
@roe3p
roe3p / mdl_Gen_ApplicationSubs.vb
Last active November 16, 2018 11:31
Excel VBA - generic application routines that usually get called from the Quick Access Toolbar. These affect the application itself, not a workbook.
'Module containing generic application routines. Any requisite functions/variables are now annotated
'in the routine header, allowing this module to be swapped out more easily
'
' (c) R Shenoy 30/07/2013
'
' Last Updated 16/11/2018
Option Explicit
@roe3p
roe3p / mdlGen_DBCommands.vb
Created March 1, 2016 16:20
Excel VBA - SQL Stored Procedure caller module
'This module was originally created by Rohan Shenoy in December 2012. It was designed to collect parameters,
'and use them to call stored procedures (in SQL Server 2005+). The primary function - sqlStoredProc takes the
'name of a stored procedure and a scripting dictionary containing a variable number of parameters (stored in
'key-value pairs). If the procedure returns a dataset, the function returns this data as an ADO recordset
'to the caller.
'
' - © R Shenoy 30/07/2013
'
'(Remember to add references to ADO and Scripting Runtime libraries to any workbooks that you add this to)
@roe3p
roe3p / A5PhoneGapVersioning.js
Last active May 18, 2016 11:12
A5 Version-checking and self-updating functions for a PhoneGap app
//''------------------------- Update Functions
//Display current version number
function displayVersion() {
{dialog.object}.setValue('AppVersion', {dialog.object}.appVars.myVersion);
{dialog.object}.setValue('AppVersion1', {dialog.object}.appVars.myVersion);
//call this function recursively until version number has been set
if ($('version_help').innerHTML != {dialog.object}.appVars.myVersion) {
setTimeout(function() { displayVersion(); } , 500);
@roe3p
roe3p / A5Authentication.js
Last active May 18, 2016 11:13
A5 Authentication functions for a PhoneGap app (requires Alpha Apps Server)
//''------------------------- Authentication Functions
function authenticate(){
var data = getLoginDetails();
jQuery.ajax({
type: "GET",
url: {dialog.object}.appVars.appURL + "ajax.a5w",
timeout: 30000,