Skip to content

Instantly share code, notes, and snippets.

View coatezy's full-sized avatar
🏍️

Tom Coates coatezy

🏍️
View GitHub Profile
@sulmanweb
sulmanweb / create_document.rb
Last active February 29, 2024 12:25
ActiveStorage file uploading in GraphQL API in Rails
# app/graphql/types/objects/document_type.rb
module Mutations
class CreateDocument < BaseMutation
description "creates a document for the user in the system"
argument :doc, ApolloUploadServer::Upload, required: true
field :document, Types::Objects::DocumentType, null: false
@JofArnold
JofArnold / BoredApeYachtClub.sol
Last active April 9, 2023 12:44
The Bored Ape Yacht Club (BAYC) Solidity Smart Contract GitHub
/**
*Submitted for verification at Etherscan.io on 2021-04-22
*/
// File: @openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
@maitrungduc1410
maitrungduc1410 / docker-compose.yml
Created November 4, 2020 03:00
Docker PHP Nginx without mouting source code to Nginx
version: '3.4'
services:
app:
image: php:7.2-fpm-alpine
restart: unless-stopped
volumes:
- ./:/var/www/html
- ./www.conf:/usr/local/etc/php-fpm.d/www.conf
webserver:
@Archie22is
Archie22is / hubspot_breadcrumbs.html
Last active March 6, 2024 21:22
Simple "hacky" HubSpot blog breadcrumb
<div id="blog--breadcrumbs">
<ul>
<li>
<a href="/" class="">Home</a>
</li>
{% if is_listing_view %}
<span class="nav--spacer">&#x203A;</span>
<li>
<strong><span class="no--link">Insights</span></strong>
</li>
@mrv1k
mrv1k / filterChromeOnUpdated.js
Last active October 19, 2022 22:09
Filter out page refresh, page loaded or chrome pages from chrome.tabs.onUpdated
const loadedTabs = {}; // global
// call within a function that hsa access to 'tab' permission
function load(tabId) {
[loadedTabs[tabId]] = response;
}
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if ((tabId !== tab.id && loadedTabs[tabId]) || /(chrome)(?:[/:-])/.test(tab.url)) return;
if (changeInfo.status === 'complete' && tab.active) {
doYourThing();
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"

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.

@dadoonet
dadoonet / search_kibana_console.txt
Last active July 4, 2024 09:28
Demo script for "A NoSQL search engine to find..." talk
### REINIT
DELETE user
PUT user
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"comments": {
@probonopd
probonopd / F1E200.md
Last active June 30, 2024 18:12
Allwinner F1E200 electronic postcard with USB Device ID 1f3a:1000

USB Device ID 1f3a:1000 Allwinner F1E200 electronic postcard

I received a promotional folder that plays a video with sound when opening the folder. This contains a rechargeable LiPo battery, a TFT display, a speaker, a power switch, a push button, 256 MB flash memory, RAM, and a CPU.

All of this for watching one 1-minute video.

What a waste! Certainly not environmentally friedndly. Until repurposed creatively!

On the back it says that the product can be sent back to the manufacturer for free recycling. Still I was wondering if I could do more with it.

@farmdawgnation
farmdawgnation / date-dot-parse.js
Last active August 29, 2015 13:56
A Date.parse implementation from Stackoverflow stuffs.
// This is a slightly modified version of two patches. The first suggested at
// http://stackoverflow.com/questions/5802461/javascript-which-browsers-support-parsing-of-iso-8601-date-string-with-date-par
// and the second, for Date.js suggested at
// http://stackoverflow.com/questions/12145437/date-js-parsing-an-iso-8601-utc-date-incorrectly
//
// Here we override the implementation of Date.parse provided by Date.js. In this implementation we
// first check to see if we can construct the date using the Date constructor. If we can, we move
// along. If we cannot, we attempt to start the Date.js grammar parser. If that, too, fails us, we
// then assume we're running in IE 8, and someone passed in an ISO8601 string, which IE8's date
// constructor won't recognize. So we try to manually parse it out, returning a Date instance.