Skip to content

Instantly share code, notes, and snippets.

Avatar

Vito Botta vitobotta

View GitHub Profile
View ttfb.sh
#!/usr/bin/env bash
#
# Shows time in seconds to first byte of a url or urls
#
# Based on a gist https://gist.github.com/sandeepraju/1f5fbdbdd89551ba7925abe2645f92b5
# by https://github.com/sandeepraju
#
# Modified by jay@gooby.org, @jaygooby
#
# Usage: ttfb [options] url [url...]
View prefetch.js
// This code is to be used with https://turbo.hotwire.dev. By default Turbo keeps visited pages in its cache
// so that when you visit one of those pages again, Turbo will fetch the copy from cache first and present that to the user, then
// it will fetch the updated page from the server and replace the preview. This makes for a much more responsive navigation
// between pages. We can improve this further with the code in this file. It enables automatic prefetching of a page when you
// hover with the mouse on a link or touch it on a mobile device. There is a delay between the mouseover event and the click
// event, so with this trick the page is already being fetched before the click happens, speeding up also the first
// view of a page not yet in cache. When the page has been prefetched it is then added to Turbo's cache so it's available for
// the next visit during the same session. Turbo's default behavior plus this trick make for much more responsive UIs (non SPA).
View prefetching.js
let lastTouchTimestamp
const prefetches = new Set()
const prefetchElement = document.createElement('link')
const isSupported = prefetchElement.relList && prefetchElement.relList.supports && prefetchElement.relList.supports('prefetch')
&& window.IntersectionObserver && 'isIntersecting' in IntersectionObserverEntry.prototype
const allowQueryString = true //'instantAllowQueryString' in document.body.dataset
const allowExternalLinks = false // 'instantAllowExternalLinks' in document.body.dataset
const useWhitelist = false //'instantWhitelist' in document.body.dataset
const mousedownShortcut = false //'instantMousedownShortcut' in document.body.dataset
View spring parallel tests
module ActiveSupport
module Testing
class Parallelization # :nodoc:
class Worker
def start
fork do
set_process_title("(starting)")
DRb.stop_service
View gist:b6bd3384b8788c270209076765170f85
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
View x.js
import { Controller } from "stimulus"
import ImageUpload from "../classes/image_upload"
export default class extends Controller {
static targets = [ "draftTextarea" ]
connect() {
console.log(12331)
// if (this.draftTextareaTarget.dataset.initialised != "true") {
this.initEditor()
@vitobotta
vitobotta / reflex.rb
Last active Apr 26, 2020
StimulusReflex working with route constraints
View reflex.rb
# frozen_string_literal: true
class StimulusReflex::Reflex
...
def request
@request ||= begin
uri = URI.parse(url)
path = ActionDispatch::Journey::Router::Utils.normalize_path(uri.path)
query_hash = Rack::Utils.parse_nested_query(uri.query)
@vitobotta
vitobotta / NginxIngress.ts
Last active Mar 25, 2020
Installing Nginx ingress controller with Pulumi
View NginxIngress.ts
import * as k8s from '@pulumi/kubernetes'
import * as pulumi from '@pulumi/pulumi'
import * as config from './config'
export interface NginxIngressArgs {
version?: pulumi.Input<string>,
namespace?: pulumi.Input<string>,
serviceType?: pulumi.Input<string>,
ingressClass?: pulumi.Input<string>,
@vitobotta
vitobotta / ZalandoPostgresCluster.ts
Last active Mar 27, 2020
Zalando Postgres Operator with Pulumi
View ZalandoPostgresCluster.ts
import * as k8s from '@pulumi/kubernetes'
import * as pulumi from '@pulumi/pulumi'
import { ZalandoPostgresOperator } from "./ZalandoPostgresOperator"
export interface ZalandoPostgresClusterArgs {
operator: pulumi.Input<ZalandoPostgresOperator>,
namespace: pulumi.Input<string>,
teamId: pulumi.Input<string>,
storageClass: pulumi.Input<string>,
storageSize: pulumi.Input<string>,
View gist:614c76f9f02d607e430264eea5c2c74b
import { Controller } from "stimulus"
import Tagify from '@yaireo/tagify'
import Rails from '@rails/ujs'
export default class extends Controller {
static targets = ["input"]
render() {
const tagify = new Tagify(this.inputTarget, {
whitelist: [],