Skip to content

Instantly share code, notes, and snippets.

View indifferentalex's full-sized avatar

Alex Vlasov indifferentalex

View GitHub Profile
@indifferentalex
indifferentalex / stability.rb
Created May 3, 2018 08:10
Potentially unstable ruby sort vs a sort that is guaranteed to be stable
unsorted_array = [21, 12, 47, 41, 33, 11, 13, 31, 43]
puts unsorted_array.sort_by { |n| n.to_s[0] }.to_s
# [12, 13, 11, 21, 33, 31, 47, 43, 41] on Mac OS X,
# [12, 11, 13, 21, 33, 31, 47, 41, 43] on most Linux distributions
puts unsorted_array.sort_by.with_index { |n, i| [n.to_s[0], i] }.to_s
# [12, 11, 13, 21, 33, 31, 47, 41, 43] even on Mac OS X, stability achieved!
@indifferentalex
indifferentalex / gist:53cd3434174903a4539d0eeec262f510
Created April 23, 2018 11:40
Find regex across all files of given format and remove all lines in which it is present
// Linux
find ./**/*.js | xargs sed -i '/regex/d'
// OS X
find ./**/*.js | xargs sed -i '' '/regex/d'