Skip to content

Instantly share code, notes, and snippets.

View nberlette's full-sized avatar
🧱
rusting away

Nicholas Berlette nberlette

🧱
rusting away
View GitHub Profile
@nberlette
nberlette / color-scheme-change.js
Created May 14, 2021 20:46
Detect system color scheme change (day->night) by @feross
module.exports = colorSchemeChange
function colorSchemeChange (onChange) {
const media = window.matchMedia('(prefers-color-scheme: dark)')
handleChange()
if ('addEventListener' in media) {
media.addEventListener('change', handleChange)
} else if ('addListener' in media) {
#!/bin/bash
[ ! -d '~/.nb-env' ] && mkdir -p '~/.nb-env'
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -P ~/.nb-env
cat <<'EOF' >> '~/.bashrc'
[ -e "$HOME/.nb-env/git-prompt.sh" ] && source "$HOME/.nb-env/git-prompt.sh"; || { wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh --no-check-certificate -P "$HOME/.nb-env" && source "$HOME/.nb-env/git-prompt.sh"; }
## color-ps1.sh by @nberlette
## I know, it's terrible
@nberlette
nberlette / BmwSvg.jsx
Created May 25, 2021 22:57
BMW Logo SVG as a React Native Component.
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Svg, { SvgProps, Use, Symbol, G, Path } from "react-native-svg"
export default function BmwSvg(props: SvgProps) {
return (
<Svg style={styles.logo} width="80%" height="80%" focusable="false" {...props}>
<Use xmlnsXlink="http://www.w3.org/1999/xlink" xlinkHref="#icon-bmw-logo-gray">
<Symbol viewBox="0 0 340 340" id="icon-bmw-logo-gray" xmlns="http://www.w3.org/2000/svg">
<G fill="#6f6f6f">
@nberlette
nberlette / encryption.js
Created May 27, 2021 05:45
ultra-lightweight encryption module for node.js
#!/usr/bin/env node
// encryption.js by @nberlette
const crypto = require('crypto')
const algorithm = 'aes-256-cbc'
const B32 = crypto.randomBytes(32)
const B16 = crypto.randomBytes(16)
const mkcipher = () => {

Raspberry Pi flavored badges!

Just a couple quick and dirty examples... see them live below the code:


![Powered by Pi](https://img.shields.io/badge/-Powered%20by%20Pi-bc1142.svg)
@nberlette
nberlette / fancy-tabs-demo.html
Created June 23, 2021 21:42 — forked from ebidel/fancy-tabs-demo.html
Fancy tabs web component - shadow dom v1, custom elements v1, full a11y
<script>
function execPolyfill() {
(function(){
// CustomElementsV1.min.js v1 polyfill from https://github.com/webcomponents/webcomponentsjs/tree/v1/src/CustomElements/v1.
/*
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
@nberlette
nberlette / require-json.mjs
Created June 28, 2021 11:12
2 lines of code to require() JSON in ES modules.
#!/usr/bin/env node
import { createRequire } from "module"
const require = createRequire(import.meta.url)
const data = require("./data.json")
@nberlette
nberlette / HTMLRewriter.js
Last active June 29, 2021 02:10
Cheerio + HTMLRewriter for Cloudflare Workers
/**
* Cheerio Wrapper for HTMLRewriter on Cloudflare Workers®
*
* Usage of cheerio here only simulates stream-oriented parser! It is slow!
*/
import cheerio from 'cheerio'
function replace(content, options) {
this[0].nodeValue = content
}
@nberlette
nberlette / HTMLRewriter.ts
Last active June 29, 2021 02:16
Cheerio + HTMLRewriter Typescript Wrapper
/**
* Cheerio Wrapper HTMLRewriter.ts
*
* Usage of cheerio here only simulates stream-oriented parser! It is slow!
* This typescript port hasn't been tested, and probably doesn't work.
*/
import cheerio from 'cheerio'
@nberlette
nberlette / autounattend.xml
Created July 19, 2021 21:32
Windows 10 Unattended Install for Raspberry Pi
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="oobeSystem">
<component name="Microsoft-Windows-International-Core" processorArchitecture="arm64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>en</SystemLocale>
<UILanguage>en-US</UILanguage>
<UILanguageFallback>en-US</UILanguageFallback>
<UserLocale>en</UserLocale>
</component>