Skip to content

Instantly share code, notes, and snippets.

View enjoylife's full-sized avatar
📖

Matthew Clemens enjoylife

📖
View GitHub Profile
@dylanowen
dylanowen / index.js
Last active May 14, 2021 19:19
Apollo Attachments Plugin
const {GraphQLList, GraphQLNonNull} = require("graphql/type/definition");
const express = require('express');
const {ApolloServer, gql} = require('apollo-server-express');
const Busboy = require('busboy');
const createError = require('http-errors');
const {initTracer} = require("jaeger-client");
const {WriteStream} = require('fs-capacitor');
const {createHash} = require('crypto');
const { printSchema, parse, visit } = require('graphql');
@TeemuKoivisto
TeemuKoivisto / Editor.tsx
Last active January 22, 2024 14:04 — forked from esmevane/index.tsx
Updated ProseMirror + React example with TypeScript and styled-components from @esmevane using NodeViews
import * as React from 'react'
import ReactDOM from 'react-dom'
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { Node, Schema } from 'prosemirror-model'
import applyDevTools from 'prosemirror-dev-tools'
import styled from 'styled-components'
// Here we have the (too simple) React component which
// we'll be rendering content into.
@sandgraham
sandgraham / iso2FlagEmoji.js
Created June 4, 2019 03:18
Convert a country's ISO-2 string to a flag emoji in a single line
const iso2FlagEmoji = iso => String.fromCodePoint(...[...iso.toUpperCase()].map(char => char.charCodeAt(0) + 127397));
iso2FlagEmoji("US"); // "🇺🇸"
@esmevane
esmevane / index.tsx
Created November 7, 2018 04:24
[ Typescript / React / ProseMirror ]: Put React components into ProseMirror NodeViews
// This assumes Styled Components is in play, as well.
//
// Here we have the (too simple) React component which
// we'll be rendering content into.
//
class Underlined extends React.Component<any, any> {
public hole: HTMLElement | null
// We'll put the content into what we render using
@horverno
horverno / quickdemo.py
Created October 26, 2018 15:18
Aruco marker-based OpenCV distance measurement
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import sys
import numpy as np
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
import cv2
import cv2.aruco as aruco
import numpy as np
import rectangleArea as ra
@cashiwamochi
cashiwamochi / simple_triangulation.cc
Last active September 16, 2023 14:19
This code is used for simple triangulation. It uses findEssentialMat, recoverPose, triangulatePoints in OpenCV. For viewer, PCL is used. You can watch 3D points and 2 camera poses. I checked alcatraz2.jpg and alcatraz1.jpg in pcv_data.zip (https://www.oreilly.co.jp/pub/9784873116075/). Perhaps there is something wrong ( actually it looks working…
#include <opencv2/opencv.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <Eigen/Core>
#include <Eigen/LU>
@ogun
ogun / outliersFilter.js
Created September 3, 2017 15:08 — forked from rmeissn/outliersFilter.js
A Javascript function to filter an array of values for outliers by using an interquartile filter
function filterOutliers(someArray) {
if(someArray.length < 4)
return someArray;
let values, q1, q3, iqr, maxValue, minValue;
values = someArray.slice().sort( (a, b) => a - b);//copy array fast and sort
if((values.length / 4) % 1 === 0){//find quartiles
@nstogner
nstogner / retry_http.go
Last active March 19, 2023 03:29
Go: Simple retry function (HTTP request)
// DeleteThing attempts to delete a thing. It will try a maximum of three times.
func DeleteThing(id string) error {
// Build the request
req, err := http.NewRequest(
"DELETE",
fmt.Sprintf("https://unreliable-api/things/%s", id),
nil,
)
if err != nil {
return fmt.Errorf("unable to make request: %s", err)

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.

@biovisualize
biovisualize / README.md
Last active September 9, 2021 16:57
d3.selection.appendHTML and appendSVG

Parse and append an HTML or SVG string. I use it a lot for appending a template, instead of generating it with d3.

d3.select('.container').appendHTML('<div><svg><g><rect width="50" height="50" /></g></svg></div>');

Unlike using .html, .appendHTML can append multiple elements

d3.select('.container').html('<span id="a"></span>');
d3.select('.container').html('<span id="b"></span>'); // will replace content
d3.select('.container').appendHTML('<span id="c"></span>'); // will append content