Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Working From Home

Rody Davis rodydavis

:octocat:
Working From Home
View GitHub Profile
@rodydavis
rodydavis / pre-commit
Created Nov 7, 2021
Simple pre commit git hook for updating a dart/flutter program version number and generating a constant for the application at runtime.
View pre-commit
#!/bin/sh
npm run version-sync
git add pubspec.yaml
git add lib/src/version.dart
@rodydavis
rodydavis / xml-node-generator.ts
Created Nov 4, 2021
Generate Formatted XML Nodes
View xml-node-generator.ts
/**
* The child of an XML node can be raw text or another xml node.
*/
export type PossibleNode = XmlNode | string;
/**
* Base XML Node type.
*/
export interface XmlNode {
tag: string;
@rodydavis
rodydavis / tree-view.ts
Created Oct 7, 2021
Lit component and function render
View tree-view.ts
import { css, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
/**
* A tree view component.
*/
@customElement("tree-view")
export class TreeView extends LitElement {
@property({ type: Object })
tree: Tree = {
View node-tree-lit.ts
import { css, html, TemplateResult } from "lit";
/**
* Tree view
*/
export declare interface TreeView {
children: BaseTreeNode[];
}
/**
@rodydavis
rodydavis / generate-readme-submodules.js
Last active Oct 4, 2021
Generate readme table for submodules of packages
View generate-readme-submodules.js
#!/usr/bin/node
// @ts-check
const fs = require('fs');
const startTag = '<!-- START_PACKAGES -->';
const endTag = '<!-- END_PACKAGES -->';
const subModuleFile = '.gitmodules';
const outputFile = `README.md`;
@rodydavis
rodydavis / flutter_alerts_example.dart
Created Sep 4, 2021
Flutter alert examples (prompt, confirm, alert).
View flutter_alerts_example.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@rodydavis
rodydavis / flutter_web_like_actions.dart
Last active Sep 4, 2021
Flutter actions for confirm, alert and prompt
View flutter_web_like_actions.dart
import 'package:flutter/material.dart';
/// Confirm with the user if they want to complete an action.
Future<bool> confirm(BuildContext context, String message, {String? title}) {
return showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(title ?? 'Confirm'),
content: Text(message),
actions: [
@rodydavis
rodydavis / dynamic_scaffold.dart
Last active Aug 24, 2021
Flutter scaffold with Navigation Rail, Bottom Navigation Bar, Drawer and Nested Navigator.
View dynamic_scaffold.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class DynamicScaffold extends StatefulWidget {
const DynamicScaffold({
Key? key,
required this.modules,
this.onGenerateRoute,
this.navKey,
}) : super(key: key);
View js_multi_file_download.js
/**
* Download a list of files.
* @author speedplane
* @link https://github.com/robertdiers/js-multi-file-download/blob/master/src/main/resources/static/multidownload.js
*/
function download_files(files) {
function download_next(i) {
if (i >= files.length) {
return;
@rodydavis
rodydavis / color-utils.js
Created Aug 5, 2021
Github Copilot Color Utils 🔥
View color-utils.js
// Convert an RGB color to HSL
function rgbToHsl(r, g, b) {
r /= 255;
g /= 255;
b /= 255;
var max = Math.max(r, g, b);
var min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0;