Skip to content

Instantly share code, notes, and snippets.

@bobisme
bobisme / tracing_subscriber.rs
Created December 15, 2023 01:37
common options for tracing subscriber logging to console
fn subscriber() -> impl tracing::subscriber::Subscriber {
use tracing_subscriber::{fmt::format::FmtSpan, prelude::*};
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::from_default_env())
.with(
tracing_subscriber::fmt::layer()
.compact()
.with_target(false)
.without_time()
.with_span_events(FmtSpan::CLOSE),
package main
import (
"fmt"
"io"
"time"
"github.com/opentracing/opentracing-go"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/rs/zerolog/log"
require 'base64'
require 'openssl'
require 'securerandom'
require 'uri'
BASE_URL = ENV['OAUTH2_BASE_URL']
REDIRECT_URI = ENV['REDIRECT_URI']
CLIENT_ID = ENV['OAUTH2_CLIENT_ID']
code_verifier = Base64.urlsafe_encode64(SecureRandom.bytes(128), padding: false)
@bobisme
bobisme / log.rb
Created July 26, 2018 16:46
Simplifying the semantic logger formatter
#!/usr/bin/env ruby
require 'logger'
require 'semantic_logger'
class KubeFmt < SemanticLogger::Formatters::Json
# redefine the defaults for log_host and log_application to be false
def initialize(
time_format: :iso_8601, log_host: false, log_application: false,
time_key: :timestamp
request = require('superagent')
request.get('http://httpbin.org/status/200')
.then(req => console.log(`got status: ${req.status}`))
.catch(err => console.error(err))
// got status: 200
request.get('http://httpbin.org/status/500')
.then(req => console.log(`got status: ${req.status}`))
@bobisme
bobisme / 20180226225426_create_cats.rb
Created May 3, 2018 00:12
rails relationship model
class CreateCats < ActiveRecord::Migration[5.0]
def change
create_table :cats do |t|
t.string :name
t.timestamps
end
end
end
require 'rails_helper'
# class Cat < ApplicationRecord
# has_many :cat_toy
# has_many :toys, through: :cat_toy, dependent: :destroy
# end
#
# class Toy < ApplicationRecord
# end
#

Database Cleaner:

group :test do ...
  gem "database_cleaner"
  ...
end

Support

@bobisme
bobisme / manywaystoskinamap.rb
Created August 4, 2017 13:52
Playing with ways to call map in Ruby.
# Originally posted here: https://glot.io/snippets/es9vhlp4hs
# ©2017 Bob. No rights reserved.
def some_func(x)
x + " sucks"
end
a = ["primus", "bob", "black hole"]
puts "\nthe most sane way"
@bobisme
bobisme / cond_wait.go
Created June 28, 2017 21:27
Example use of Cond.Wait
package main
import (
"fmt"
"sync"
"time"
)
func waitForSignal() {
var m sync.Mutex