Skip to content

Instantly share code, notes, and snippets.

View nkostic's full-sized avatar

Nenad Kostic nkostic

View GitHub Profile
@nkostic
nkostic / LastOccuranceIndexSQL.sql
Created March 8, 2012 11:59
Last Occurance Index in SQL
declare @SomeString varchar(30)
set @SomeString='ABC-AB-B-ABC-ABCD-0001-001-X'
-- We are searching for last occurrence of '-' in @SomeString
select LEN(@SomeString)-(CHARINDEX('-',REVERSE(@SomeString))) as LastOccuranceIndex
--LastOccuranceIndex should return 26 :P
@nkostic
nkostic / ArrayOfStructuresToQuery.cfm
Created March 26, 2012 12:56
Convert Array Of Structures To Query
<cffunction name="ArrayOfStructuresToQuery" access="public" returntype="query" output="false">
<cfargument name="StructArray" type="any" required="true" />
<cfscript>
KeyList=StructKeyList(arguments.StructArray[1]);
qbook = QueryNew(KeyList);
for(i=1; i <= ArrayLen(arguments.StructArray); i=i+1){
QueryAddRow(qbook);
for(y=1;y lte ListLen(KeyList);y=y+1){
QuerySetCell(qbook, ListGetAt(KeyList,y), arguments.StructArray[i][ListGetAt(KeyList,y)]);
@nkostic
nkostic / GetMaxValueOfKeyInStructArray.cfm
Created March 26, 2012 13:40
Get Max Value of Key InS truct Array
<cffunction name="GetMaxValueOfKeyInStructArray" access="public" returntype="numeric" output="false">
<cfargument name="StructArray" type="any" required="true" />
<cfargument name="StructKey" type="any" required="true" />
<cfscript>
sqlMax=0;
temp=0;
for(i=1; i <= ArrayLen(arguments.StructArray); i=i+1){
if(StructFind(arguments.StructArray[i], "#arguments.StructKey#")){
temp=StructFind(arguments.StructArray[i], "#arguments.StructKey#");
if(temp>sqlMax){
@nkostic
nkostic / DropAllTablesInMSSQLDatabase.sql
Created April 6, 2012 13:11
Drop All Tables in Database MSSQL
use database_name
declare @i int
set @i = 0
while (@i<99)
begin
declare @table_name varchar(100)
declare table_list cursor for
select name from sysobjects o2 where xtype='U' and
not exists (
select * from sysforeignkeys k
@nkostic
nkostic / html5Page.html
Created April 8, 2012 23:02
Html5 Page
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>HTML5 Page</title>
</head>
<body>
<header>
<nav>
<!-- Menu -->
@nkostic
nkostic / getComponentMetaData.cfm
Created April 24, 2012 21:50
getComponentMetaData
<cfscript>
objContactsMeta = getComponentMetaData('path.to.component');
</cfscript>
<cfdump var="#objContactsMeta#" />
@nkostic
nkostic / kill_database_users.sql
Created November 8, 2012 18:25
kill_database_users
USE [master]
GO
/****** Object: StoredProcedure [dbo].[kill_database_users] Script Date: 11/08/2012 19:24:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[kill_database_users] @arg_dbname sysname with recompile
AS
@nkostic
nkostic / mssql_db_backup.sql
Created November 29, 2012 00:26
MSSQL Database Insatance Backup sql part
-- =============================================
-- Author: Nenad Kostic
-- Create date: 11/29/2012
-- Description: Backup Instance
-- Big Thanks : Dragan Zdravkovic
-- =============================================
USE MASTER
DECLARE
@nkostic
nkostic / mssql_db_backup.bat
Created November 29, 2012 00:30
MSSQL Database Insatance Backup BAT part
ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO SELECT SERVER or 0 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - BACKUP INSTANCE SERVERNAME\INSTANCENAME
ECHO 0 - EXIT
@nkostic
nkostic / cfcapp.sublime-snippet
Created January 31, 2014 03:27
application.cfc snippet
<snippet>
<content>
<![CDATA[
<cfcomponent
displayname="Application"
output="true"
hint="Handle the application.">