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 / Test-IsAdmin.ps1
Created April 18, 2016 09:58
Test for admin privileges in powershell.
function Test-IsAdmin {
try {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal -ArgumentList $identity
return $principal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )
} catch {
throw "Failed to determine if the current user has elevated privileges. The error was: '{0}'." -f $_
}
<#
@AndiSHFR
AndiSHFR / DateTimeExtension.cs
Created April 22, 2016 09:56
IsValidSqlDateTime
internal static class SqlMvaLibExtensions {
private static readonly DateTime _minSqlDateTime = new DateTime(1753, 1, 1);
private static readonly DateTime _maxSqlDateTime = new DateTime(9999, 12, 31, 23, 59, 59, 997);
internal static bool IsValidSqlDateTime(this System.DateTime dt) {
return (dt >= _minSqlDateTime && dt <= _maxSqlDateTime);
}
}
@AndiSHFR
AndiSHFR / post-curl
Created July 15, 2016 18:36 — forked from creativepsyco/post-curl
POST request Via CURL in MAC OS X
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"userid": "mohit", "password":"password"}' http://mmedwebdemo.ddns.comp.nus.edu.sg:8080/comp.nuhs.jaxb/api/usr/login
@AndiSHFR
AndiSHFR / WiFiAutoSelector.h
Last active February 13, 2023 06:23
ESP8266 : WiFiAutoSelector - Pick wifi with best signal from a list and connect to it.
/**
* WiFiAutoSelector.h - Include file for class WiFiAutoSelector
* Copyright (c) 2016 Andreas Schaefer <[email protected]>
*
* A class to pick a wifi network from a list, based on the
* highest receive signal strength, and connect to it.
* Inspired by "WiFiMulti"
*
* This source code is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@AndiSHFR
AndiSHFR / mixColor.js
Created August 15, 2016 14:03
mixColor : Javascript function to mix percentual between a start and an end color
var mixColor = function(hexColorStart, hexColorEnd, percent) {
/* Example:
var startColor = '#FF8000';
var endColor = '#0080FF';
var t = [];
for(var i=0; i < 100; i += 10 ) {
var mix = mixColor(startColor, endColor, i);
t.push('<span style="display: inline-block; width: 20px; height: 60px; background-color: ' + mix + '">&nbsp;</span>');
}
document.getElementById('demo').innerHTML = t.join('');
@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
@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 / 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 / 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 / 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) {