Skip to content

Instantly share code, notes, and snippets.

View bryanmylee's full-sized avatar
🔬
Learning new things!

Bryan Lee bryanmylee

🔬
Learning new things!
View GitHub Profile
@bryanmylee
bryanmylee / httpd.conf
Last active November 10, 2020 03:57
Configuring Apache to handle HTTPS and act as a proxy for other services
# If HTTPS is required on any project, this is a simple way
# of encrypting the connection without modifying the project.
# Add these settings to /etc/httpd/conf/httpd.conf
# Redirect HTTP requests to HTTPS and rewrite the URL
Listen 80
<VirtualHost *:80>
ServerName "ryver.life"
ServerAlias "www.ryver.life"
RewriteEngine on
@bryanmylee
bryanmylee / automate.sh
Created June 29, 2021 05:26
tmux automation
LIST=... # should be a space-separated list of items
for VAR in $LIST
do
tmux new-window -n "{name}" "{command}; /bin/bash" &
done
@bryanmylee
bryanmylee / popup.ts
Created December 9, 2021 14:33
Send message to the active tab of a browser extension
async () => {
const [activeTab] = await browser.tabs.query({
active: true,
currentWindow: true,
});
const response = await browser.tabs.sendMessage(activeTab.id, {
greeting: "hello",
});
console.log("main.js received response:", response);
};
@bryanmylee
bryanmylee / dataclass_nonhashed_field.py
Created December 13, 2021 19:28
Using `field` to customize field properties
from dataclasses import dataclass, field
from typing import FrozenSet
@dataclass(frozen=True, eq=True)
class Ingredient:
id: str
g_per_ml: float
substitution_ids: FrozenSet[str] = field(
default_factory=lambda: frozenset(), compare=False
@bryanmylee
bryanmylee / storybook-webpack.js
Last active December 28, 2021 07:59
Custom Webpack config for Storybook
const webpackConfig = require("./webpack.config.js");
module.exports = {
...,
core: {
builder: "webpack5",
},
webpackFinal: (config) => ({
...config,
module: {
@bryanmylee
bryanmylee / Button.stories.svelte
Created January 4, 2022 11:17
A comprehensive Svelte Storybook template
<script lang="ts">
import { Meta, Template, Story } from '@storybook/addon-svelte-csf';
import Button from './Button.svelte';
</script>
<!-- More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export -->
<!-- More on argTypes: https://storybook.js.org/docs/svelte/api/argtypes -->
<Meta
title="Example/Button"
component={Button}
@bryanmylee
bryanmylee / tailwindcss-var-color-opacity.js
Last active January 5, 2022 19:02
TailwindCSS variable colors with `bg-opacity`
const colors = require('tailwindcss/colors');
/** Colors must be defined in a special format.
--color-s-0: 255, 255, 255;
--color-s-50: 248, 250, 252;
--color-s-100: 241, 245, 249;
--color-s-200: 226, 232, 240;
--color-s-300: 203, 213, 225;
--color-s-400: 148, 163, 184;
--color-s-500: 100, 116, 139;
@bryanmylee
bryanmylee / Generics.svelte
Created January 16, 2022 17:36
Generic type definitions for Svelte components
<script lang="ts">
type T = $$Generic
interface $$Slots {
default: { // slot name
item: T
index: number
}
}
export let items: T[] = []
</script>
@bryanmylee
bryanmylee / .storybook_main.cjs
Last active November 7, 2022 17:20
Svelte (kit) + Storybook + Webpack 5 configuration to support all modern features (optional chaining and nullish coalescence in templates)
const path = require('path');
const postcss = require('postcss');
const preprocess = require('svelte-preprocess');
const replaceFileExtension = (filePath, newExtension) => {
const { name, root, dir } = path.parse(filePath);
return path.format({
name,
root,
dir,
@bryanmylee
bryanmylee / type_factory_method.py
Created March 15, 2022 13:00
Add type hints to a Python factory method
from typing import Type, TypeVar
T = TypeVar('T', bound='TrivialClass')
class TrivialClass:
# ...
@classmethod
def from_int(cls: Type[T], int_arg: int) -> T:
# ...