Skip to content

Instantly share code, notes, and snippets.

View jfbrennan's full-sized avatar

Jordan Brennan jfbrennan

View GitHub Profile
@jfbrennan
jfbrennan / linear-dialog-flow.jsx
Last active November 20, 2023 21:18
Linear dialog flow
// A version of https://www.esveo.com/en/blog/O5/ using native dialog API and no extra abstractions.
function App() {
const [users, setUsers] = useState([
{ id: 1, name: "peter" },
{ id: 2, name: "tony" },
]);
const [userToBeDeleted, setUserToBeDeleted] = useState(null);
const dialog = useRef();
function handleDeleteClick(user) {
@jfbrennan
jfbrennan / riot-template.html
Last active March 29, 2020 21:03
Riot component with all the basics
<my-todos>
<p>Todo count: {state.todos.length}</p>
<input ref="newTodo" type="text">
<button onclick="{add}">Add</button>
<ul if="{state.todos.length}">
<li each="{(todo, i) in state.todos}" key="{i}">{todo} <button onclick="{e => remove(i)}">Remove</button></li>
</ul>
<script>
export default {
@jfbrennan
jfbrennan / vue-sfc-template.html
Last active March 29, 2020 20:48
Vue Single File Component with all the basics
<template>
<p>Todo count: {{todos.length}}</p>
<input ref="newTodo" type="text">
<button v-on:click="add">Add</button>
<ul v-if="todos.length">
<li v-for="(todo, i) of todos" :key="i">{{todo}} <button v-on:click="remove(i)">Remove</button></li>
</ul>
</template>
<script>
@jfbrennan
jfbrennan / num-to-digits.js
Last active March 28, 2020 07:26
JavaScript convert number to array of digits
const num = 123
let digits
// Option A
digits = num.toString().split('').map(Number)
console.log(digits) // [1, 2, 3]
// Option B
digits = Array.from(String(num), Number)
console.log(digits) // [1, 2, 3]
@jfbrennan
jfbrennan / find-pairs.js
Created March 17, 2020 06:09
Student-Course Pairs
const studentCoursePairs1 = [
["58", "Linear Algebra"],
["94", "Art History"],
["94", "Operating Systems"],
["17", "Software Design"],
["58", "Mechanics"],
["58", "Economics"],
["17", "Linear Algebra"],
["17", "Political Science"],
["94", "Economics"],
@jfbrennan
jfbrennan / ReactAlert.js
Last active January 25, 2018 19:28
Alert UI component rebuilt to compare Riot vs Slim vs Polymer vs Vue vs React and more
import React, {Component} from 'react'
import PropTypes from 'prop-types'
class ReactAlert extends Component {
static defaultProps = {
icon: null,
msg: '',
type: 'info',
autodismiss: 0,
onRemoveAlert: () => {}