Skip to content

Instantly share code, notes, and snippets.

View tschoffelen's full-sized avatar

Thomas Schoffelen tschoffelen

View GitHub Profile
"use client";
import React, { useEffect, useRef } from "react";
import axios from "axios";
const loadMapkitJs = () =>
new Promise((resolve) => {
if (typeof window === undefined) {
return;
}
import fs from "node:fs/promises";
import { createProcessor } from "@mdx-js/mdx";
const pipeline = createProcessor();
const flattenItems = (items) => {
return items.reduce((acc, item) => {
acc[item.name] = item.value;
return acc;
}, {});
@tschoffelen
tschoffelen / export-roam-note.js
Created March 5, 2021 09:52
Little tool I built for myself to export roam notes.
window.exportRoamNote = async () => {
const noteId = Math.round(Math.random()*10000) + '-note.md';
const body = $('.roam-body .roam-app .roam-main .roam-article')[0].innerHTML;
const boxUrl = 'https://mrm5dm6of9.execute-api.eu-west-1.amazonaws.com/'
+ 'production/box/get-url?filename='+noteId+'&'
+ 'contentType=text%2Fplain';
const res = await fetch(boxUrl, {method: 'GET' });
const {key, url} = await res.json();
await fetch(url, {
@tschoffelen
tschoffelen / frontend_uploader-utils.js
Last active July 25, 2020 20:54
Example of uploading files to S3 via signed URLs.
// Frontend uploader example
// URL for your lambda function
const backendUrl = "https://xxxxxx.execute-api.eu-west-1.amazonaws.com/production/create-upload-url"
// Accepts a File object here, for example from
// a <input type="file"> or drag and drop action
const uploadFile = (file) => {
const filename = encodeURIComponent(file.name)
const type = encodeURIComponent(file.type)
@tschoffelen
tschoffelen / README.md
Last active May 30, 2020 22:55
Some of my personal Git utility bash commands.

Git utilities

A set of personal bash commands that help me with day-to-day Git operations.

master

Checkout and pull the master branch from origin.

feat <my-new-feature>

Checkout a new feature branch in the form of feat/my-new-feature from master.

@tschoffelen
tschoffelen / dashbored-spec.md
Last active April 9, 2018 12:38
Spec for dashboard files for the Dashbored app for Apple TV.

Dashbored file specification

Dashboard files for the Dashbored app for Apple TV and iPhone are JSON files with a certain structure.

A dashboard file should be a JSON object with at least the keys title and sections, and optionally the key theme.

Title

The title key should always exist and contain a string value of the title you want displayed at the top of the dashboard.

@tschoffelen
tschoffelen / dashboard.json
Last active April 9, 2018 12:32
Example dashboard JSON for the Dashbored app for Apple TV.
{
"title": "Our chicken farm",
"theme": {
"dashboardBackgroundColor": "green",
"dashboardBackgroundImage": "https://www.bestwallpaperhd.com/wp-content/uploads/2015/06/Little-Chickens.jpg",
"dashboardTitleColor": "#ffffff",
"headerColor": "#666",
"textColor": "#121212",
"backgroundColor": "#ffffff",
"borderRadius": 10,
<?php
// Set username
$username = 'tschoffelen';
// Get page contents
$content = file_get_contents('https://dribbble.com/' . $username . '?page=1&per_page=12');
// Parse page content into $shots array
$shots = [];
@tschoffelen
tschoffelen / webpack.config.js
Last active September 27, 2018 09:21
Tricking PHPStorm in supporting React Native path aliases.
/**
* Why is this here you ask? React Native doesn't use Webpack. True. This file is here to trick
* IDEA in recognizing module aliases (see the package.json files in some of the subdirs).
* Nice solution? No. Does it work? Sure.
* Tracker URL: https://youtrack.jetbrains.com/issue/WEB-23221
*
* - TS
*/
const fs = require('fs')
@tschoffelen
tschoffelen / install.php
Last active February 12, 2024 09:20
A simple PHP script that automatically downloads and unzips the latest version of Wordpress in the current directory (./), so that I don't have to download it and upload it to my server through FTP manually.
<?php
echo '<pre>';
echo '<span style="color:blue">DOWNLOADING...</span>'.PHP_EOL;
// Download file
file_put_contents('wp.zip', file_get_contents('https://wordpress.org/latest.zip'));
$zip = new ZipArchive();
$res = $zip->open('wp.zip');
if ($res === TRUE) {