Skip to content

Instantly share code, notes, and snippets.

@peterhpchen
peterhpchen / StopwatchDemo.cs
Last active April 10, 2020 09:53
Stopwatch Demo
using System;
using System.Diagnostics;
using System.Threading;
public class Program
{
public static void Main()
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
@peterhpchen
peterhpchen / fileInDirectoryToASCII.ps1
Created January 21, 2019 07:09
Encoding all file in directory to ASCII
# Encoding current path all asp file to ASCII
get-childitem -path *.asp -force | foreach-object { (get-content $_.fullname) | set-content $_.fullname }
@peterhpchen
peterhpchen / prevent-browser-basic-auth-popup.js
Last active September 16, 2018 16:17
Node.js Basic Auth which Using Custom Authorization Type to Prevent Browser Basic Auth Popup.
const http = require('http');
// const BASIC_AUTH = 'xBasic'; // Use Custom Authorization Type to Prevent Browser Basic Auth Popup
const BASIC_AUTH = 'Basic';
const USER_NAME = 'admin';
const PASSWORD = 'admin';
function unauthorizedRes(res) {
// res.statusCode = 400; // Use Status Code Except 401
res.statusCode = 401;
@peterhpchen
peterhpchen / add-user.asp
Last active August 31, 2018 06:00
Grafana Add, Update and Delete User To Organization and Login
<!--#include file="../util/base64.asp"--><!--https://stackoverflow.com/a/506992-->
<!--#include file="../util/jsonObject.class.asp" --><!--https://github.com/rcdmk/aspJSON-->
<%
response.LCID = 1046
Function AddGrafanaUser(grafanaUrl, basicAuth, orgName, userName, password, userRole)
Dim orgId
orgId = getOrgId(grafanaUrl, orgName, basicAuth)
If orgId = 0 then
@peterhpchen
peterhpchen / SaveTwoUShortToSingleUInt.cs
Created August 22, 2018 06:41
Use UInt to save two UShort
public static uint saveTwoUShortToSingleUInt(ushort low, ushort high)
{
uint result = low;
result += (uint)high << 16;
return result;
}
public static Tuple<ushort, ushort> convertSingleUIntToTwoUShort(uint integer)
{
ushort low = Convert.ToUInt16(integer & 0xFFFF);
// Sample
var layers = [
{
name: "Project",
count: 1
},
{
name: "Node",
count: 1
},
@peterhpchen
peterhpchen / Microsoft.PowerShell_profile.ps1
Last active January 3, 2018 01:06
Power Shell Custom Functions
# Add a Custom Function: https://blogs.technet.microsoft.com/heyscriptingguy/2006/11/21/how-can-i-add-a-function-to-a-windows-powershell-script/
# create today logbook
# reference: https://routley.io/tech/2017/11/23/logbook.html
function lb {
$date = Get-Date -DisplayHint date -format yyyy-MM-dd;
code --new-window \logbook\$date.md
}
@peterhpchen
peterhpchen / answer4.md
Created October 19, 2017 11:57
Pre-Test Question 4

本來

function createArrayOfFunctions(y) {
    var arr = [];
    for (var i = 0; i < y; i++) {
        arr[i] = function (x) { return x + i; }
    }
    return arr;
}
@peterhpchen
peterhpchen / answer3.cs
Created October 19, 2017 11:55
Pre-Test Question 3
using System;
namespace Question3
{
public class Class1
{
//要檢查的最大Fibonacci的N, 題目為60
private static int MAXNOFFIBONACCI = 60;
public int[] nextFibonacci(int[] numArray)