Skip to content

Instantly share code, notes, and snippets.

$(function() {
var poll_interval = 2
var relatizer = function(){
var dt = $(this).text(), relatized = $.relatizeDate(this)
if ($(this).parents("a").length > 0 || $(this).is("a")) {
$(this).relatizeDate()
if (!$(this).attr('title')) {
$(this).attr('title', dt)
}
@taf2
taf2 / converter.js
Last active January 12, 2021 22:52
A version of https://github.com/javl/image2cpp for the command line
/*
originally from https://raw.githubusercontent.com/javl/image2cpp/master/index.html
converted to command line interface
node converter.js -f arduino -m horizontal1bit -b transparent -n VariableName -i input.bmp -o output.c
head output.c
// 'input', 100x100px
const unsigned char VariableName [] PROGMEM = {
0x00, 0x00, 0x00
options:

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.

/***************************************************
This is a library for the Adafruit TTL JPEG Camera (VC0706 chipset)
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/397
These displays use Serial to communicate, 2 pins are required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
@taf2
taf2 / action.js
Last active August 24, 2020 15:13
Salesforce - Query for custom field picker in CallTrackingmetrics.
/*
Usage:
Configure in Variables the objects and their properties you want to search.
The properties must include an Id and Name. Optionally you can include an Email property.
You can use https://app.calltrackingmetrics.com/salesforce/object_attributes.json?object=<insert your object type here>
to discover the internal names for your Object's properties.
@taf2
taf2 / action.js
Created August 6, 2020 15:56
Update Zendesk Ticket with Chat Transcription
exports.handler = function(event, context, callback) {
const ticket = event.activity.custom_fields.zd_ticket.match(/\d+/)[0]
const data = {call_id: event.activity.id, ticket_id: ticket, ticket_data: {"ticket": {"status": "open", "comment": { "body": event.activity.chat_transcription }}}}
var authHeaders = {'Authorization': process.env.ZDAuth};
context.http_post('https://app.calltrackingmetrics.com/api/v1/accounts/25/zendesk/update_ticket',
JSON.stringify(data),
authHeaders).then(function(request) {
@taf2
taf2 / action.js
Last active September 30, 2022 13:33
Query Salesforce Used in a picker to select an object in salesforce by user input e.g. phone number or name
const jsforce = require('jsforce');
function phoneQuery(number, objects) {
let digits = number.replace(/\D/g,'').split("");
if (digits.length > 10) {
let country_code = digits.shift();
}
let npa = [];
npa.push(digits.shift());
npa.push(digits.shift());
openssl s_client -connect yum.datadoghq.com:443
CONNECTED(00000003)
140536412514128:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:794:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 289 bytes
---
@taf2
taf2 / oauth2-client.rb
Created April 28, 2020 14:17
Example oauth2 client for CallTrackingMetrics.com
#
# Example OAuth2 Application for CallTrackingMetrics.com
# Users are redirected to your application and prompted to allow access to their CallTrackingMetrics account with the given permissions
# After accepting they are redirected back to your applicaiton's /authorize URL via GET request.
# In this request you will receive a 'code' that you must send via a POST request back to CTM to get an access token and refresh token.
# Later when the access token expires you can renew it via the refresh request.
#
require 'sinatra'
require 'curb'
require 'uri'
@taf2
taf2 / sofar.sh
Created March 31, 2020 04:04
here's the output so far
pt-slave-restart --master-uuid 393fa485-fd5d-11e7-8c56-0e15b1b77760 --host localhost -u root
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
together with SSL_ca_file|SSL_ca_path for verification.
If you really don't want to verify the certificate and keep the
connection open to Man-In-The-Middle attacks please set
SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
at /usr/bin/pt-slave-restart line 3842.