Skip to content

Instantly share code, notes, and snippets.

View Geesu's full-sized avatar

Josh Becker Geesu

View GitHub Profile
@Geesu
Geesu / assets.rake
Created December 8, 2014 16:55
Disable asset precompilation on heroku
Rake::Task["assets:precompile"].clear
namespace :assets do
task 'precompile' do
puts "Not pre-compiling assets..."
end
end
@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:8476386
Created January 17, 2014 16:27
Example of a archive_command bash script to replication to 2 different servers. Like the local_backup_script.sh referenced here: http://www.postgresql.org/docs/current/static/continuous-archiving.html#BACKUP-SCRIPTS
#!/bin/bash
FAIL=0
job_1 = `rsync -aq $1 postgres@server1:/var/lib/postgresql/9.2/archive/$2`
job_2 = `rsync -aq $1 postgres@server2:/var/lib/postgresql/9.2/archive/$2`
$job_1 & pid_1=$! ; $job_2 & pid_2=$!
echo "Spawned replication processes $pid_1 AND $pid_2"
# 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 / 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 / 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