Skip to content

Instantly share code, notes, and snippets.

View Geesu's full-sized avatar

Josh Becker Geesu

View GitHub Profile
# frozen_string_literal: true
# Instruments a block of code and reports it to scout as a background job. Do NOT use this to instrument a small
# amount of code. It is meant to be used for ruby processes that we start and scout doesn't automatically instrument.
class ScoutReporter
@@agent = nil
def self.initialize_agent
if @@agent.nil?
@@agent = ::ScoutApm::Agent.instance
public class XmlSerializer
{
// save
public static Boolean Serialize(String Path, object Object)
{
try
{
File.Delete(Path);
}
catch { }
@Geesu
Geesu / service_objects.md
Last active January 6, 2019 04:02
Ruby Service Objects - Why and How

Ruby Service Objects

Why

Service objects are great when you need to abstract/move some business logic away from a model or controller. Ideally you keep your models and controllers small and simple.

By moving logic to a service object it is also much easier to test what you're trying to achive, instead of needing to put multiple methods within a model/controller which may only exist for that one purpose.

How - Example 1

@Geesu
Geesu / remove_exif.rb
Created August 6, 2018 18:59
Remove all metadata from MP4 files for better processing by Plex.
#!/bin/ruby
# This script specifically removes all meta data from mp4 files which have a title property set
# You can't change this property unfortunately. So instead just strip all metadata from the file with ffmpeg.
# Requirements:
# brew install ffmpeg exiftool
# Just set the path to all of your mp4 files
path = '/Volumes/Movies'
@Geesu
Geesu / detect.rb
Created July 10, 2018 20:07
Detect invalid characters in a CSV
contents = File.read('/Users/Josh/Desktop/1.csv')
unless contents.valid_encoding?
invalid_characters = {}
contents.each_line.with_index do |line, idx|
invalid_characters[idx] ||= []
line.each_char do |char|
unless char.valid_encoding?
#!/usr/bin/env python3
# Copyright (c) 2016 MariaDB Corporation Ab
#
# Use of this software is governed by the Business Source License included
# in the LICENSE.TXT file and at www.mariadb.com/bsl.
#
# Change Date: 2019-01-01
#
# On the date above, in accordance with the Business Source License, use
@Geesu
Geesu / gist:a4e02b029309e58bfa009b5c46022a95
Created February 20, 2017 21:16
Compiling MaxScale 2.0 branch on Ubuntu 16.04.2
# Avro C prereqs
# https://github.com/grisha/json2avro/blob/master/avro-c/INSTALL
apt-get install cmake g++ pkg-config asciidoc libsnappy-dev libboost-dev libboost-filesystem-dev libboost-iostreams-dev libboost-program-options-dev libboost-system-dev
# Install jansson 2.3.x
wget http://www.digip.org/jansson/releases/jansson-2.3.1.tar.gz
tar -xzvf jansson-2.3.1.tar.gz
cd jansson-2.3.1
./configure
make && make install && ldconfig
@Geesu
Geesu / gist:949a9660a3068e9f48b2877ec395da06
Created January 16, 2017 19:26
Production maxscale configuration
[maxscale]
threads=1
[server1]
type=server
address=ip.address
port=3306
protocol=MySQLBackend
[MySQL Monitor]
@Geesu
Geesu / limit_decoder.rb
Created December 5, 2016 19:03
Limit VTDecoderXPCService using cputhrottle
#!/usr/bin/env ruby
# Configure the below
process_name = 'VTDecoderXPCService'
cpu_percentage = 10
raise 'Must run as root' unless Process.uid == 0
restricted_pids = []
throttle_pids = []
@Geesu
Geesu / instrument.rb
Created May 16, 2016 13:43
Instrumental wrapper
class Instrument
class << self
attr_reader :instrumental_agent
def time(metric, *args, &block)
instrumental_agent.time(metric, *args, &block)
end
def increment(metric, *args)
instrumental_agent.increment(metric, *args)