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 / string-extension-_toBool.js
Created March 24, 2016 13:23
Javascript: String.prototype._toBool
// We extend the string object with a little helper function
// to convert a boolean value from a string to bool.
// var flag = "true"._toBool
Object.defineProperty(String.prototype, "_toBool", {
get : function() {
return (/^(true|1)$/i).test(this);
}
});
@AndiSHFR
AndiSHFR / RemoveBT.cmd
Created April 5, 2016 19:20
Remove $WINDOWS.~BT
// go inside that folder:
cd /d "C:\$Windows.~BT"
// take over ownership
takeown /f *.* /R /D Y
// (go for coffee, takes a minute)
// grant full rights to everyone
icacls *.* /grant Everyone:(OI)(CI)F /T
@AndiSHFR
AndiSHFR / sqlserver-opentrans.sql
Created April 7, 2016 09:27
Sql Server Open Trans
SELECT
GETUTCDATE() AS [DateTime],
[s_tst].[session_id],
[s_es].[login_name] AS [Login Name],
DB_NAME (s_tdt.database_id) AS [Database],
[s_tdt].[database_transaction_begin_time] AS [Begin Time],
[s_tdt].[database_transaction_log_bytes_used] AS [Log Bytes],
[s_tdt].[database_transaction_log_bytes_reserved] AS [Log Rsvd],
[s_est].text AS [Last T-SQL Text],
[s_eqp].[query_plan] AS [Last Plan]
@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 $_
}
<#
use mysql;
update user set password=PASSWORD("UlE3x:rtRt$12") where User='vhost_4711';
flush privileges;
@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 / 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