Skip to content

Instantly share code, notes, and snippets.

@rhymes
rhymes / rails_cache_store_increment.rb
Created April 10, 2020 13:34
Rails cache stores, increment test
require "tempfile"
cache_stores = %i[
file_store
mem_cache_store
memory_store
null_store
redis_cache_store
]

Hi everyone

Problem with some code highlighting for this part of the series. An issue has been opened.

Welcome to part 7 of the series but before we jump in let's recap what we did in the sixth part:

  • homework: Create a Context Accounts with a User Schema and a Users Migration with username field and password field.

  • Bonus: Create a User query and a User type.

@rhymes
rhymes / event.json
Last active September 9, 2019 16:43 — forked from lightalloy/event.json
{
"data": {
"id": "01DM3JNTH0PBE8DRD60A8BFQD0",
"type": "webhook_event",
"attributes": {
"event_type": "article_created",
"timestamp": "2019-09-06T15:21:56Z",
"payload": {
"data": {
"id": "335",
@rhymes
rhymes / detect_c_gems.rb
Created September 3, 2019 08:38
Detect with gems have C-based extensions
# from https://mailchi.mp/railsspeed/the-gvl-and-c-extensions-a-cooperative-partnership
require 'rubygems'
gems = Gem::Specification.each.select { |spec| spec.extensions.any? }
puts gems.map(&:full_name).map {|x| x.split('-', 2).first }.sort.uniq
@rhymes
rhymes / go-dep-multistage.Dockerfile
Last active March 13, 2019 20:00
Sample docker multistage file with Go
FROM golang:alpine AS builder
# install packages
RUN apk add --no-cache curl git
# https://golang.github.io/dep/docs/FAQ.html#how-do-i-use-dep-with-docker
RUN curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x /usr/local/bin/dep
RUN mkdir -p $APP_PATH
WORKDIR $APP_PATH
COPY Gopkg.toml Gopkg.lock ./
@rhymes
rhymes / remove_first_char.rb
Created October 18, 2018 13:17
Benchmark removal of the first character
# from https://stackoverflow.com/a/3614592/4186181
require 'benchmark'
N = 1_000_000
class String
def eat!(how_many = 1)
self.replace self[how_many..-1]
end
@rhymes
rhymes / colorkeyvaluerender.py
Created April 7, 2018 12:39
Structlog key value renderer with colors
# coding: utf-8
'Color key value renderer'
import itertools
from io import StringIO
import colorama
import structlog
LEVEL_COLORS = {
@rhymes
rhymes / AppInputFile.vue
Created March 27, 2018 08:07
buefy app input file
<template>
<div class="container">
<b-field>
<b-tooltip
:label="tooltipLabel"
position="is-right"
type="is-dark"
animated>
<b-field>
@rhymes
rhymes / kvencoder.go
Last active June 29, 2022 19:13
key=value encoder for logging library zap (a giant hack)
// adapted from https://github.com/uber-go/zap/blob/master/zapcore/json_encoder.go
// and https://github.com/uber-go/zap/blob/master/zapcore/console_encoder.go
package logging
import (
"encoding/base64"
"encoding/json"
"math"
"sync"
"time"