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 / 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 / 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 <asc@schaefer-it.net>
*
* 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 / 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 / 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 / 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 / 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 / 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
use mysql;
update user set password=PASSWORD("UlE3x:rtRt$12") where User='vhost_4711';
flush privileges;
@AndiSHFR
AndiSHFR / md5.js
Created March 24, 2016 13:24
Create MD5 hash in javascript
var MD5 = function(s) {
function L(k,d) { return(k<<d)|(k>>>(32-d))}
function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=(k&2147483648);I=(G&1073741824);d=(k&1073741824);x=(G&1073741823)+(k&1073741823);if(I&d){return(x^2147483648^F^H)}if(I|d){if(x&1073741824){return(x^3221225472^F^H)}else{return(x^1073741824^F^H)}}else{return(x^F^H)}}
function r(d,F,k){return(d&F)|((~d)&k)}
function q(d,F,k){return(d&k)|(F&(~k))}
function p(d,F,k){return(d^F^k)}
function n(d,F,k){return(F^(d|(~k)))}
function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}
function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}
@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);
}
});