Skip to content

Instantly share code, notes, and snippets.

@gregeng
gregeng / version_sort.rb
Created October 14, 2013 18:57
version_sort, accounts for differences in the letter before .ext by converting it to the ASCII code first
require 'pry'
class Array
def version_sort
array = self.sort_by do |file|
file.gsub(/[a-z].ext/) {|x| x.ord }
end
array.sort_by do |item|
item.scan(/\d+|[a-z]*/).collect do |el|
@gregeng
gregeng / api_parsing.rb
Last active December 25, 2015 13:09
Safe For Work Reddit
require 'json'
require 'rest_client'
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json'))
html_reddit = "<html><head></head><body><ul>"
reddit_hash["data"]["children"].each do |post|
next if post["data"]["over_18"] == true
@gregeng
gregeng / serialize.rb
Created October 15, 2013 13:29
to-do serialization
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :progress # :progress, :html, :textmate
end