Skip to content

Instantly share code, notes, and snippets.

View AndiSHFR's full-sized avatar
💭
Designing and Coding...

Andreas Schaefer AndiSHFR

💭
Designing and Coding...
View GitHub Profile
@AndiSHFR
AndiSHFR / script-database-users-and-permissions.sql
Last active March 8, 2020 07:46
Script Sql Server Database Users and Permissions
/**
* script-database-users-and-permissions.sql
*
* Copyright (C) 2020 by Andreas Schaefer <[email protected]>
*
* Create a t-sql script that can be used to restore users and
* persmissions on a sql server database
*
* Notes:
* - The script will not script built-in accounts or accounts like '##MS%##'
@AndiSHFR
AndiSHFR / time-range.html
Created December 3, 2019 10:06
IDEA: How to handle relative time ranges in query selection parameters
<!DOCTYPE html>
<!--
IDEA: How to handle relative time ranges in query selection parameters
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
@AndiSHFR
AndiSHFR / basic-jquery-widget-example.js
Created October 21, 2019 12:48
Basic jQuery Widget Example
/**
* Minimal jQuery Widget Example
* Author: Andreas Schaefer <[email protected]>
*
* Usage:
*
* <div id="myCoolWidget"></div>
*
* ...
*
@AndiSHFR
AndiSHFR / constants.cc
Created May 3, 2018 06:44
Node.js - add constat values to exports of native addon
#define NODE_SET_MEMBER(target, name, value) \
do { \
v8::Isolate* isolate = target->GetIsolate(); \
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
v8::Local<v8::String> constant_name = v8::String::NewFromUtf8(isolate, (name)); \
(target)->Set(v8::Local<Value>::New(isolate, \
v8::String::NewFromUtf8(isolate, name)), \
value); \
} while (0)
@AndiSHFR
AndiSHFR / naturalSort.js
Created June 22, 2017 08:50
Javascript code to do a natural sort.
function naturalSort(ar, index){
var L= ar.length, i, who, next,
isi= typeof index== 'number',
rx= /(\.\d+)|(\d+(\.\d+)?)|([^\d.]+)|(\.(\D+|$))/g;
function nSort(aa, bb){
var a= aa[0], b= bb[0], a1, b1, i= 0, n, L= a.length;
while(i<L){
if(!b[i]) return 1;
a1= a[i];
@AndiSHFR
AndiSHFR / sort-objects.js
Last active June 22, 2017 08:21
Javascript code to show how to sort array of objects by object properties.
!function() {
function _dynamicSortMultiple(attr) {
/*
* save the arguments object as it will be overwritten
* note that arguments object is an array-like object
* consisting of the names of the properties to sort by
*/
var props = arguments;
return function (obj1, obj2) {
@AndiSHFR
AndiSHFR / omnisharp.json
Last active May 4, 2017 10:22
Formatting options for OmniSharp. Place this file in your project folder. Use CTRL+SHIFT+V to reformat the source code.
{
"FormattingOptions": {
"NewLine": "\n",
"UseTabs": false,
"TabSize": 2,
"IndentationSize": 2,
"SpacingAfterMethodDeclarationName": false,
"SpaceWithinMethodDeclarationParenthesis": false,
"SpaceBetweenEmptyMethodDeclarationParentheses": false,
"SpaceAfterMethodCallName": false,
@AndiSHFR
AndiSHFR / convert-base2-to-int.sql
Created April 27, 2017 11:14
Sql Server: Convert base2 string into integer
-- This sql snippet converts a base2 string (0 and 1 bits)
-- into an integer value
DECLARE @bitmask VARCHAR(8) = '10000000'
-- Bitposition: 76543210
DECLARE @intValue INT
;WITH bits(pos) AS (
select 1 union select 2 union select 3 union select 4 union
@AndiSHFR
AndiSHFR / SqlServerPagingExample.sql
Last active January 30, 2017 09:28
Paging Example in Sql Server (like mysql LIMIT+OFFSET)
-- Pageing in SQL Server like mysql (LIMIT + OFFSET)
DECLARE @Offset INT = 3
DECLARE @Limit INT = 10
;WITH Results_CTE AS
(
SELECT
COUNT(*) OVER () as TotalRows,
ROW_NUMBER() OVER (ORDER BY name) AS RowNum,
id, name, crdate, refdate
@AndiSHFR
AndiSHFR / lib-php-direct-call-protection.php
Created January 17, 2017 11:18
Protection against direct script calling.
<?php
// Protect agains direct calls from the web browser
if(1 == count(get_included_files())) {
http_response_code(404);
die( '<h1>404 Not Found</h1><p>The page that you have requested could not be found.</p>');
}
// More library code here