Skip to content

Instantly share code, notes, and snippets.

@dukemai
dukemai / test
Created October 8, 2019 07:47
test utils
import app from '../../../app';
import apiHelpers from '@/server/api/tests/apiHelpers';
const request = require('supertest');
const tokenValue = apiHelpers.createToken('anotheruser@expressen.se');
export const httpRequest = type => (endpoint, includeAuthenCookie = true) => argsObj => {
const req = request(app)[type](endpoint);
if (includeAuthenCookie) {
@dukemai
dukemai / cancellablePromise.js
Created November 26, 2019 13:28
cancellable promise
export const CANCEL_REJECTION = 'CANCEL_REJECTION';
export default function createPromiseCanceller() {
let racesInProgress;
let promiseRejector;
let racePromise;
function resetCanceller() {
racesInProgress = 0;
@dukemai
dukemai / puppeteer.js
Created November 27, 2019 22:11
puppeteer screenshot
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const page = await browser.newPage();
await page.goto('https://website.com', { waitUntil: 'networkidle0', timeout: 60000 });
await page.setViewport({ width: 1920, height: 1080 });
await page.screenshot({ path: 'website.png', fullPage: true });
@dukemai
dukemai / cheatsheets
Last active May 6, 2024 10:36
mdx cheatsheets
custom container
::: section header
# header
content
:::
oc -n bn-klara-goran2-prod describe pod goran2-7fd8fc7f47-pptll
@dukemai
dukemai / connect.js
Created January 4, 2020 09:32
azure-blob-connect
const storage = require('azure-storage');
const memoizeOne = require('memoize-one');
const streams = require('memory-streams');
const csvtojsonV2 = require('csvtojson');
const Json2csvParser = require('json2csv').Parser;
const getFileService = memoizeOne(conn => storage.createFileService(conn));
const getFiles = (conn, map) =>
new Promise((resolve, reject) => {
@dukemai
dukemai / content
Last active May 6, 2024 10:35
useful notes
- Research has shown that the ideal line length is about 65 characters. Anywhere between 45 and 85 is generally seen as acceptable, in the context of a roman alphabet.
- You may have heard that using the wildcard selector (*) is bad practice. Some will tell you that it is slow, and can affect the overall performance of your page.
Happily, this is not true. It's been debunked again and again. Even in 2009, when computers were slower and browsers were less optimized, this wasn't an issue. Performance concerns around the wildcard selector are a particularly-resilient urban legend.
@dukemai
dukemai / searchHandling.js
Created November 23, 2020 16:57
dream object usage
const {
get,
getOr,
pipe,
map,
flatMap,
toPairs,
compact,
find,
pathEq,
@dukemai
dukemai / command line cheatsheet
Last active May 6, 2024 10:35
gcloud commands
https://cloud.google.com/sdk/docs/cheatsheet
curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
sudo bash install-monitoring-agent.sh
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sudo bash install-logging-agent.sh
@marv7000
marv7000 / perm_mode_str.h
Created May 5, 2024 22:40
[C23] Compile time constant file permission flags from a string
#pragma once
/*
* Scary abuse of the sizeof syntax so static_assert gets evaluated.
* If it passes, we don't want to modify the result though, so AND with 0.
* This is illegal in C++!
*/
#define MODE_ASSERT(x, m) sizeof(struct { static_assert(x, m); char _ghost; }) & 0
/*
@marcospgp
marcospgp / SafeTask.cs
Last active May 6, 2024 10:34
Cancel async tasks in Unity upon exiting play mode
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace UnityUtilities
{
/// <summary>
/// A replacement for `Task.Run()` that cancels tasks when entering or
/// exiting play mode in the Unity editor (which doesn't happen by default).