Skip to content

Instantly share code, notes, and snippets.

View csymlstd's full-sized avatar

Casey Milstead csymlstd

View GitHub Profile
@thomhines
thomhines / example.js
Last active April 18, 2020 21:57
Capacitor iosMotion - Simple, partially-functional workaround for Capacitor Motion plugin (uses Native API instead of Web API). Place the .swift and .h files in the root of your App folder in Xcode, then add the javascript stuff to your app's code.
// Register the plugin with Capacitor
import { Plugins } from '@capacitor/core';
const { Keyboard } = Plugins;
// ORIENTATION
// Start tracking device orientation. This must be run in order for the following event listener to work
iosMotion.getOrientation()
@malle-pietje
malle-pietje / index.html
Last active December 14, 2023 06:34
Redirection to a custom URL from the UniFi controller JSP-based captive portal
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title><unifi txt="Redirector" /></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="0;url=https://<YOUR CAPTIVE PORTAL URL>/<unifi var="mac" />/<unifi var="ap_mac" />">
</head>
<body>
</body>
</html>
@culttm
culttm / axios.refresh_token.js
Created October 5, 2017 18:46
axios interceptors for refresh token
axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
const originalRequest = error.config;
if (error.response.status === 401 && !originalRequest._retry) {
originalRequest._retry = true;
@javilobo8
javilobo8 / download-file.js
Last active April 9, 2024 12:01
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@mtrunkat
mtrunkat / docker-mongo-repair
Last active March 19, 2024 06:28
Run "mongo --repair" in Docker container that cannot start because of MongoDB error
#!/bin/bash
# See https://github.com/docker-library/mongo/pull/63
docker run --rm --volumes-from my-mongo-server mongo unlink "/data/db/mongod.lock"
docker run --rm --volumes-from my-mongo-server mongo --repair
@clemlatz
clemlatz / self-signed-ssl-certificate.md
Last active April 22, 2024 12:30
Setup a self-signed SSL certificate with Nginx (server and browser)

1. Configure server: Nginx

Create the certificate:

$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

Create a strong Diffie-Hellman group:

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
@idleberg
idleberg / atom-macos-context-menu.md
Last active April 27, 2022 00:37
“Open in Atom” in macOS context-menu

Open in Atom

  • Open Automator
  • Create a new Service
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
  • Set the script action to /usr/local/bin/atom -n "$@"
  • Set “Pass input” to as arguments
  • Save as Open in Atom
@Tset-Noitamotua
Tset-Noitamotua / Vagrantfile
Last active October 9, 2018 03:44
Vagrantfile for Windows 10 with MS Edge from modern.ie[1] - stackoverflow.com discussion: http://stackoverflow.com/questions/38869921/how-to-change-default-admin-user-name-and-password-of-a-modern-ie-windows-10-vir
Vagrant.configure("2") do |config|
config.vm.box = "windows10_msedge"
config.vm.boot_timeout = 500
config.vm.network "private_network", ip: WIN10_MSEDGE_IP
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.name = "windows10_msedge"
vb.cpus = 1
vb.memory = 2048
end
@chuckreynolds
chuckreynolds / wp-local-media-nginx.txt
Last active October 6, 2023 09:01
Local NGINX WordPress Media Uploads Fallback. Substitute {PROD} for the domain to use images from.
location ~* ^.+\.(svg|svgz|jpg|jpeg|gif|png|ico|bmp)$ {
try_files $uri @image_fallback;
}
location @image_fallback {
proxy_pass http://{PROD};
}