Skip to content

Instantly share code, notes, and snippets.

View iMerica's full-sized avatar

Michael iMerica

  • Austin, Texas
View GitHub Profile
@iMerica
iMerica / filter.js
Last active July 30, 2018 06:35
Work At A Startup Job Filter
const findJobs = (remote, min_salary) => {
return window.TOP_LEVEL_PROPS.companies.filter(
company => company.jobs.filter(
job => ((job.remote_ok === remote) && (job.salary_max >= min_salary))
).length > 0
)
}
@iMerica
iMerica / authentication.py
Last active September 7, 2018 00:27
Custom Auth for Django/DRF that allows for multiple API Tokens per user.
from rest_framework.authentication import TokenAuthentication
from .models import RESTAPIToken
class CustomRestAPIAuthentication(TokenAuthentication):
""" Custom Authentication """
def get_model(self):
return RESTAPIToken
@iMerica
iMerica / functional-utils.js
Created December 11, 2018 18:25 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@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
@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 / 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 / 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 / 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 / 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 / Dockerfile
Last active March 4, 2020 20:58
Python 3.8 + Alpine + GDAL
FROM python:3.8.0-alpine
EXPOSE 8000
MAINTAINER "iMichael" <imichael@pm.me>
WORKDIR /app
RUN apk add --no-cache \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \