Skip to content

Instantly share code, notes, and snippets.

View iMerica's full-sized avatar

Michael iMerica

  • Austin, Texas / SF, Bay Area
View GitHub Profile
@iMerica
iMerica / Anchor.jsx
Created January 30, 2020 23:54
Fixes Anchor Focus Issue
import React, { forwardRef, useState, cloneElement, useContext, useEffect } from 'react'
import { normalizeColor } from "grommet/utils/colors"
import { Box, ThemeContext } from "grommet"
import { StyledAnchor } from "grommet/components/Anchor/StyledAnchor"
export const Anchor = forwardRef(
(
{
a11yTitle,
children,
@iMerica
iMerica / Button.jsx
Last active January 30, 2020 23:37
Fixes Grommet Focus Issue
import React, { Children, forwardRef, cloneElement, useContext, useState } from "react";
import { StyledButton } from "grommet/components/Button/StyledButton"
import { colorIsDark, normalizeColor } from "grommet/utils/colors"
import { defaultProps } from "grommet"
import { normalizeBackground } from "grommet/utils/background"
import { ThemeContext } from "grommet"
const Button = forwardRef(
(
{
@iMerica
iMerica / app.jsx
Last active January 13, 2020 22:04
Tabs ++ in Grommet
class App extends Component {
state = {
activeTab: 0,
}
setTab = (i) => {
this.setState({activeTab: i})
}
@iMerica
iMerica / Dockerfile
Last active March 4, 2020 20:58
Python 3.8 + Alpine + GDAL
FROM python:3.8.0-alpine
EXPOSE 8000
MAINTAINER "iMichael" <[email protected]>
WORKDIR /app
RUN apk add --no-cache \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
@iMerica
iMerica / upgrade_pip_packages.py
Last active October 9, 2019 17:17 — forked from serafeimgr/upgrade_pip_packages.py
A python script to upgrade all outdated python packages.
"""
This script upgrades all outdated python packages.
"""
from multiprocessing import Pool, cpu_count
from subprocess import PIPE, Popen
def run_command(command):
"""
@iMerica
iMerica / cache_mixin.py
Last active September 28, 2019 19:07
Michael's Django Cache Mixin for CBVs
from django.views.decorators.cache import cache_page
# MIT License
# Copyright (c) 2019 @iMerica
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@iMerica
iMerica / curl_time.sh
Created April 18, 2019 21:45
Quick and dirty Performance Metrics using only Curl
#!/usr/bin/env bash
# I found this in my ZSH profile and I forgot where I got it from. If you wrote it, Thanks!
curl -so /dev/null -w " namelookup: %{time_namelookup}s\n connect: %{time_connect}s\n appconnect: %{time_appconnect}s\n pretransfer: %{time_pretransfer}s\n redirect: %{time_redirect}s\nstarttransfer: %{time_starttransfer}s\n-------------------------\n total: %{time_total}s\n" "$@"
@iMerica
iMerica / README.md
Last active April 2, 2019 01:45
A Pattern for Auth based Routing using Redux, React Router

A Pattern for Auth based Routing using Redux, React Router

Assumptions

  • Token based authentication or JWT. This one is good for Django Rest Authentification.
  • The first line of defense in protecting sensitive data is your REST API and its auth system, not your React SPA. This solution is just for intelligent routing, not protecting sensitive data.
  • Redux or equivalent state management framework that allows you to easily connect components to a single source of truth state.

Summary

If you're familiar with the React concept of "lifting state up",

@iMerica
iMerica / index.js
Created December 28, 2018 21:18
Django/DRF File Uploading to S3
const notifyDjango = (url) => {
// Record the URL of the file you've uploaded along with any data
// that is relevent to you.
}
const uploadToS3 = (file, url) => {
// Upload the file here
// See https://git.io/fhIz5 as a great example of handling all S3 upload edge cases.
}
@iMerica
iMerica / fizz-buzz.sh
Last active December 20, 2018 23:09
CLI Fizz Buzz One Liner
#!/usr/bin/env bash
# MIT License
# Copyright (c) 2018 @iMerica (Michael)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is