Skip to content

Instantly share code, notes, and snippets.

Avatar
🐈
pssst! Klaus is hiring

andreas andreasvirkus

🐈
pssst! Klaus is hiring
View GitHub Profile
View stringToHtml.ts
export function stringToHtml(html: string): ChildNode {
var template = document.createElement('template')
html = html.trim() // Never return a text node of whitespace as the result
template.innerHTML = html
return template.content.firstChild
}
// usage:
const div = stringToHtml('<div><span>nested</span> <span>stuff</span></div>')
View style.css
.toaster {
position: fixed;
z-index: 11;
}
.toast {
display: flex;
position: fixed;
bottom: 0;
left: 50%;
View vueQuerySync.js
import Vue from "vue";
function setupWatchers(data = []) {
if (!(this instanceof Vue)) throw new Error("Persistence plugin needs to be called from a Vue component");
if (!data) return;
const query = new URLSearchParams(location.search);
data.forEach((name) => {
const key = `${this.$options.name}_${name}`;
if (query.has(key)) this[name] = JSON.parse(query.get(key));
View sheets_slack_notification.gs
function buildReport() {
const ss = SpreadsheetApp.getActive();
const data = ss.getSheetByName('SUMMARY').getRange("A1").getValues();
const payload = buildAlert(data);
Logger.log(data);
sendAlert(payload);
}
function buildAlert(data) {
const mrr = data[0][0];
View ordinal.js
export const ordinal = (num) => {
const suffix = ['th', 'st', 'nd', 'rd']
const value = val % 100
return val + (suffix[(value - 20) % 10] || suffix[value] || suffix[0])
}
View HandleChunkLoadFailurePlugin.js
const prettier = require("prettier");
const pluginName = "HandleChunkLoadFailurePlugin";
/**
* This Webpack plugin calls `window._chunkHandler.handleVersionChange()` when loading a chunk fails
*/
class HandleChunkLoadFailurePlugin {
constructor(options = {}) {
this.options = Object.assign({}, options);
View apache_utils.sh
# Command to check access count per unique IP
tail -n 10000 /var/log/apache2/access.log | awk '{print $1}'| sort| uniq -c| sort -nr| head -n 10
# Command to check access per unique pathname
awk {'print $7'} /var/log/apache2/access.log | sort -nk1 | uniq -c | less
View sql_get_size.sql
SELECT table_schema
AS "Database", SUM(data_length + index_length) / 1024 / 1024
AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
View generateCspSha.js
import crypto from 'crypto'
const generateChecksum = str =>
crypto
.createHash('sha256')
.update(str, 'utf8')
.digest('base64')
const script =
'if (localStorage.getItem("theme")) document.documentElement.dataset.theme = localStorage.getItem("theme")'
View prune_old_logs.sh
# Prune all log files whose modified time is older than 6 days
find /var/log -mindepth 1 -mtime +5 -delete