Skip to content

Instantly share code, notes, and snippets.

View MaxPleaner's full-sized avatar

Max Pleaner MaxPleaner

View GitHub Profile
@MaxPleaner
MaxPleaner / patch_activerecord_find_by.rb
Created December 27, 2016 21:21
Patch ActiveRecord's find_by to prevent errors because of strings passed to numeric columns
# This can be added to config/initializers
class ActiveRecordPatch
# find_by(numeric_column: "foo") converts "foo" to 0 before searching.
# This is probably not desired.
# This patch prevents this behavior
#
def self.validate_input_for_numeric_conditions(class_or_query, conditions)
@MaxPleaner
MaxPleaner / todo.txt
Created December 16, 2016 18:09
todo
https://github.com/tmux-plugins/tmux-continuum
https://github.com/tmux-plugins/tmux-resurrect
@MaxPleaner
MaxPleaner / file.rb
Created November 30, 2016 16:04
get all stack overflow answers as plaintext
require 'dotenv'
require 'pry'
require 'ruby-stackoverflow'
require 'rest_client'
Dotenv.load
RubyStackoverflow.configure do|config|
config.client_key = ENV["SO_PRIVATE"]
#!/usr/bin/env ruby
ext = ARGV[0]
prefix = ARGV[1]
glob = Dir.glob "./*.#{ext}"
glob.each do |path|
`mv -- "#{path}" "#{prefix}#{File.basename path}"`
end
@MaxPleaner
MaxPleaner / git_tricks.txt
Last active November 22, 2016 20:10
git tricks
Stop a file from being tracked, but only for the local repo:
git update-index --assume-unchanged nbproject/project.properties
to revert that state:
git update-index --no-assume-unchanged
too see all files being ignored in this way:
@MaxPleaner
MaxPleaner / core_util.rb
Last active November 22, 2016 20:10
core util
require 'set'
class CoreUtil
def find_array_duplicates(array)
set = Set.new
array.select { |elem| !set.add?(elem) }
end
end
test
@MaxPleaner
MaxPleaner / benchmark_test_suite.rake
Created November 9, 2016 23:31
benchmark a rspec test suite
# It turns out this is pretty much unnecessary
# because "rspec --profile" does the same thing
# However I think this version's output is a
# bit prettier.
task :benchmark_test_suite => :environment do
require 'rspec_profiling'
require 'rspec_profiling/console'
@MaxPleaner
MaxPleaner / atomicity_test_with_concurrent_threads_and_global_variables.rb
Last active November 6, 2016 20:28
Atomicity test with concurrent threads and global variables
module AtomicityTestWithConcurrentThreadsAndGlobalVariables
# parameters
Global_in_count = 5000
Thread_count = 500
# global stores
Global_in = 1.upto(Global_in_count).to_a
Global_out = []
@MaxPleaner
MaxPleaner / file.rb
Last active October 24, 2016 07:15
example of using class exec
# When including Sounds, some other modules/constants are loaded as well
module Sounds
def self.included(base)
super
base.class_exec do
# these are all defined elsewhere
include Sounds::Introduction
include Sounds::Base
include Sounds::Loader
include Sounds::Effects