Skip to content

Instantly share code, notes, and snippets.

View supermacro's full-sized avatar
🎯
Focusing

Gio supermacro

🎯
Focusing
View GitHub Profile
@supermacro
supermacro / reactions.html
Created June 10, 2015 00:22
Reaction Tester
<!doctype html>
<html>
<head>
<title>Reaction Tester</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="main.css">
@supermacro
supermacro / index.html
Created October 10, 2016 21:26
Skeleton layout example
<!--HEADER-->
<header>
<div class="container">
<div class="row">
<div class="twelve columns">
<nav>
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Work</a></li>
@supermacro
supermacro / binary-tree.elm
Created February 23, 2018 03:12
Elm Examples
{- OVERVIEW ------------------------------------------------------
A "Tree" represents a binary tree. A "Node" in a binary tree
always has two children. A tree can also be "Empty". Below I have
defined "Tree" and a number of useful functions.
This example also includes some challenge problems!
-----------------------------------------------------------------}
@supermacro
supermacro / schema.ts
Created November 1, 2018 20:29
types for defining JSON schemas
type Required<T> = {
[K in keyof T]: Schema<T>
}
interface ObjectSchema<T> {
type: 'object'
required: Array<keyof T>
properties: Required<T>
}
export const fetchComments = async ({
postId,
host
}: RequestInfo): Promise<Result<Array<Comments.Schema>, string>> => {
try {
const comments = await db(Comments.Table.name)
.select(everything(Comments.Table))
.join(
Posts.Table.name,
`${Comments.Table.name}.${Comments.Table.cols.post_id}`,
const BUFFER_CAPACITY: usize = 4;
pub struct Buffer {
size: usize,
read_idx: usize,
write_idx: usize,
buffer: [u8; BUFFER_CAPACITY] // unsigned 8bit integer
}
{-
Note that we use the `riskyRequest` function because this
webapp uses Cookies for authentication.
These cookies come from a different domain than the one
that host this app
-}
module Api exposing
( adminSignup
, adminSignin
, getAdminSession
@supermacro
supermacro / lolo.ts
Created April 9, 2019 15:47
TypeSafe `pick` and `omit` from lodash
const pickFunc = <T extends {}, K extends keyof T>(
obj: T,
predicate: (k: string) => boolean
): Pick<T, K> =>
Object
.keys(obj)
.filter(predicate)
.reduce((filteredObj: Pick<T, K>, key) => ({
...filteredObj,
[key]: obj[key as keyof T]
@supermacro
supermacro / ResponsiveNav.elm
Last active November 9, 2019 02:10
Creating a responsive / toggleable responsive navigation bar with elm and tailwindcss
module ResponsiveNav exposing (withVnav, update, Msg)
import Html exposing (Html, div, header, nav)
import Html.Attributes as Attributes exposing (class)
import Html.Events exposing (onClick)
import UI.Icons exposing (logo, hamburger)
type alias Model a =
{ a |
@supermacro
supermacro / tree.elm
Created November 18, 2020 15:04
Thinking about tree structures in Elm
-- A tree contains 2 kinds of nodes
-- at depths 1 through 2 you will have a node with a 'replies' field
-- at depth 3 the node is missing a 'replies' field
type alias TreeNode a =
{ a
| body : String
}