Skip to content

Instantly share code, notes, and snippets.

🤖
Building AI

Michael iMerica

🤖
Building AI
  • Obscura
  • Austin, LA & NYC.
Block or report user

Report or block iMerica

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@iMerica
iMerica / upgrade_pip_packages.py
Last active Oct 9, 2019 — forked from serafeimgr/upgrade_pip_packages.py
A python script to upgrade all outdated python packages.
View upgrade_pip_packages.py
"""
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 Sep 28, 2019
Michael's Django Cache Mixin for CBVs
View cache_mixin.py
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 Apr 18, 2019
Quick and dirty Performance Metrics using only Curl
View curl_time.sh
#!/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 Apr 2, 2019
A Pattern for Auth based Routing using Redux, React Router
View README.md

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 Dec 28, 2018
Django/DRF File Uploading to S3
View index.js
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 Dec 20, 2018
CLI Fizz Buzz One Liner
View fizz-buzz.sh
#!/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 / functional-utils.js
Created Dec 11, 2018 — forked from bendc/functional-utils.js
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
View functional-utils.js
// 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 / authentication.py
Last active Sep 7, 2018
Custom Auth for Django/DRF that allows for multiple API Tokens per user.
View authentication.py
from rest_framework.authentication import TokenAuthentication
from .models import RESTAPIToken
class CustomRestAPIAuthentication(TokenAuthentication):
""" Custom Authentication """
def get_model(self):
return RESTAPIToken
@iMerica
iMerica / filter.js
Last active Jul 30, 2018
Work At A Startup Job Filter
View filter.js
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 / docker-compose.yml
Last active Jan 14, 2019
Gitlab Docker Runners
View docker-compose.yml
version: '2'
services:
dind:
restart: always
privileged: true
volumes:
- /var/lib/docker
image: docker:18.06.0-ce-dind
command:
- --storage-driver=overlay2
You can’t perform that action at this time.