Skip to content

Instantly share code, notes, and snippets.

View shaicoleman's full-sized avatar

Shai Coleman shaicoleman

View GitHub Profile
require 'minitest/autorun'
require './flatten'
describe 'Flatten' do
it 'invalid parameter' do
assert_raises(ArgumentError) do
ArrayUtils.flatten(1)
end
end
it 'empty array' do
module ArrayUtils
def self.flatten(a, ret = [])
raise ArgumentError, 'parameter must be an array' unless a.is_a?(Array)
a.each do |i|
if i.is_a?(Array)
flatten(i, ret)
else
ret << i
end
end
@shaicoleman
shaicoleman / nim-install.sh
Last active August 29, 2015 14:20
Nim install script
#!/bin/bash
echo Installing dependencies...
# APT based systems. Tested on: Ubuntu 14.04
[[ -f /etc/debian_version ]] && sudo apt-get update
[[ -f /etc/debian_version ]] && sudo apt-get -y install git mercurial curl build-essential libzip-dev
# RPM based systems. Tested on: CentOS 7
[[ -f /etc/redhat-release ]] && [[ -x /usr/bin/sudo ]] || yum -y install sudo
[[ -f /etc/redhat-release ]] && sudo yum -y groupinstall "Development Tools" --exclude=subversion --exclude='systemtap*' --exclude=valgrind
@shaicoleman
shaicoleman / patcher.rb
Last active July 5, 2023 18:03
Initializer for mitigating CVE-2013-0156 and CVE-2013-0333 on all versions of rails
def rails_between(min, max)
Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new(min) && Gem::Version.new(Rails::VERSION::STRING) <= Gem::Version.new(max)
end
if rails_between('3.0.0', '3.0.18') || rails_between('3.1.0', '3.1.9') || rails_between('3.2.0', '3.2.10')
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
end
if rails_between('2.0.0', '2.3.14')
ActionController::Base.param_parsers.delete(Mime::XML)
end