Skip to content

Instantly share code, notes, and snippets.

View leefsmp's full-sized avatar

Philippe Leefsma leefsmp

View GitHub Profile
@james2doyle
james2doyle / lodash.memo.ttl.ts
Last active August 15, 2022 21:20
Use lodash memoize with a TTL. Allows calls to be cached by time as well as argument values
import { memoize, partialRight } from 'lodash';
/**
* Custom memoize that uses a 1 minute TTL
* @see https://lodash.com/docs/4.17.15#memoize
*/
const memo = partialRight(memoize, function memoResolver(...args) {
// or for one hour: (new Date()).getHours();
const time = (new Date()).getMinutes();
@obskyr
obskyr / stream_response.py
Last active April 2, 2024 09:53
How to stream a requests response as a file-like object.
# -*- coding: utf-8 -*-
import requests
from io import BytesIO, SEEK_SET, SEEK_END
class ResponseStream(object):
def __init__(self, request_iterator):
self._bytes = BytesIO()
self._iterator = request_iterator
@Purush0th
Purush0th / jspdf.plugin.text-align.js
Last active November 23, 2020 18:47
Text alignment for jsPDF 💥
(function (api, $) {
'use strict';
api.writeText = function (x, y, text, options) {
options = options || {};
var defaults = {
align: 'left',
width: this.internal.pageSize.width
}