Skip to content

Instantly share code, notes, and snippets.

require 'pg'
uri = ''
file = File.open('tmp/write.txt', 'w')
while true do
begin
conn = PG.connect( uri )
@brycesch
brycesch / Gemfile
Last active February 5, 2020 05:24
stream w2json to kafka
source 'https://rubygems.org'
gem 'eventmachine'
gem 'eventmachine-tail'
gem 'yajl'
gem 'ruby-kafka'
@brycesch
brycesch / artillery_ws_config.yml
Last active May 15, 2019 19:37
artillery load testing config for phoenix channels
config:
target: "ws://localhost:4000/socket/websocket?client_id=fb55a707-8f3a-4900-b095-0b971550c61d&vsn=2.0.0"
phases:
- duration: 60 # Test for 60 seconds
arrivalRate: 100 # Every second, add 10 users
rampTo: 1000 # And ramp it up to 100 users in total over the 60s period
name: "Ramping up the load"
- duration: 120 # Then resume the load test for 120s
arrivalRate: 100 # With those 100 users we ramped up to in the first phase
rampTo: 1000 # And keep it steady at 100 users
@brycesch
brycesch / webvtt.rb
Last active March 22, 2019 16:38
Ruby library to generate webvtt formatted transcripts from an array of timestamped words.
module Webvtt
DEFAULT_MAX_CHAR_LENGTH = 40
class Cue
attr_accessor :start, :end, :words
def initialize(words)
self.words = words
end
def to_s
@brycesch
brycesch / tails_slack.sh
Last active April 8, 2021 17:40
tail file to webhook endpoint
#!/bin/bash
# chmod a+x tails.sh
# nohup ./tails.sh foobar.log webhook_url &
# use nohup if you want the cammand to persist after your session ends
#
# slack
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done

Keybase proof

I hereby claim:

  • I am brycesch on github.
  • I am brycesch (https://keybase.io/brycesch) on keybase.
  • I have a public key ASDG86SfmH1zppp8yJMGD5ITxTJMuj5bFjTp_7j244zmDgo

To claim this, I am signing this object:

@brycesch
brycesch / mysql_string_sanitizer.rb
Created September 6, 2017 16:30
String sanitizer for MySQL's default utf8 encoding - You can avoid needing to use this by switching to utf8mb4
class MysqlStringSanitizer
def self.sanitize(str)
str = str.force_encoding('utf-8').encode
clean_text = ""
# emoticons 1F601 - 1F64F
regex = /[\u{1f600}-\u{1f64f}]/
clean_text = str.gsub regex, ''
#dingbats 2702 - 27B0
@brycesch
brycesch / backup.sh
Last active June 1, 2017 21:04
create encrypted database backups
#!/bin/bash
# Do the following to create the pub.pem
# openssl rsa -in id_rsa -outform pem > id_rsa.pem
# openssl rsa -in id_rsa -pubout -outform pem > id_rsa.pub.pem
# gen rand key
openssl rand -base64 32 > key.bin
# timestamp for dump
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
super(options, response_status)
end
module_name = ARGV[0]
return "No module name given" unless module_name
files = Dir['/**/*.rb']
files.each do |f|
f = File.open(f, "r+")
lines = f.readlines
f.close
output = File.new(f, "w")
output.write "module #{module_name}\n"