Skip to content

Instantly share code, notes, and snippets.

View klinkby's full-sized avatar

Mads Breusch Klinkby klinkby

View GitHub Profile
@klinkby
klinkby / secure-ssh.sh
Created November 20, 2023 09:52
Set file permissions on ssh keys
cd ~ && chmod 600 ~/.ssh/* && chmod 700 ~/.ssh && chmod 644 ~/.ssh/*.pub
static async Task<Encoding> GetEncodingFromStream(Stream s, int bufferSize, CancellationToken ct)
{
if (!s.CanSeek || !s.CanRead)
{
// can't touch this
return Encoding.Default;
}
byte[] buffer = new byte[bufferSize];
int bytesRead = await s.ReadAsync(buffer, 0, buffer.Length, ct);
let securityHeaders = {
"Content-Security-Policy": "default-src 'self' 'unsafe-inline'",
"X-Xss-Protection": "1; mode=block",
"X-Frame-Options": "DENY",
"Referrer-Policy": "strict-origin-when-cross-origin",
"Permissions-Policy": "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()"
};
addEventListener('fetch', event => {
event.respondWith(addHeaders(event.request));
<!DOCTYPE html>
<html lang="da-DK">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div>
<textarea id="emails"></textarea>
<button id="doMail"></button>
@klinkby
klinkby / boinc-rosetta.sh
Created April 11, 2020 19:58
Shell script for running rosetta on a plain
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install boinc-client
sudo /etc/init.d/boinc-client restart
boinccmd --project_attach https://boinc.bakerlab.org/rosetta/ {your-weak-key-here}
boinccmd --set_run_mode always
boinccmd --set_network_mode always
boinccmd --get_simple_gui_info
Function CallbackWrapper {
param (
[string]$callbackScript,
[object]$param,
[int]$order
)
$callback = [ScriptBlock]::Create($callbackScript)
return [PSCustomObject]@{
Result = $callback.InvokeReturnAsIs($param)
Order = $order
@klinkby
klinkby / perf-coll.js
Created September 28, 2017 07:49
Collect key performance metrics, dump in document then reload page for another run.
(function () {
"use strict";
var t = performance.timing,
t1 = t.navigationStart,
arr = [t.responseEnd - t1, t.domContentLoadedEventStart - t1, t.loadEventEnd - t1],
storage = sessionStorage,
storageKey = "perf-coll",
coll = JSON.parse(storage.getItem(storageKey) || "[]"),
serialized;
coll.push(arr);
@klinkby
klinkby / textbox-clientaddin.js
Last active August 29, 2017 12:02
NAV client control with a simple multiline text box
/**
* NAV client control with a simple multiline text box
* Exposes the following methods:
* GetText() : string
* SetText(string)
* GetReadOnly() : boolean
* SetReadOnly(boolean)
*
* And the following events:
* Blur
@klinkby
klinkby / Get-Spreadsheet.ps1
Last active June 3, 2019 17:35
Powershell script to read Excel spreadsheet contents
function Get-Spreadsheet {
param(
[Parameter(Mandatory = $true)]
[ValidateScript({ Test-Path $_ -PathType Leaf })]
[string]$Path
)
try {
[DocumentFormat.OpenXml.Packaging.SpreadsheetDocument] | Out-Null
}
catch {
@klinkby
klinkby / restart-dlink-921.sh
Created March 18, 2017 16:32
Shell script for remote reboot the D-Link 921 router