Skip to content

Instantly share code, notes, and snippets.

require 'dotenv'
require 'ruby/openai'
require 'csv'
require 'parallel'
require 'tmpdir'
require 'ruby-progressbar'
Dotenv.load()
training_data = Dir.glob("training-data/**/*.txt")
record = Post.new(:title => 'Yay', :body => 'This is some insert SQL')
# easiest way to achieve this is by calling protected #arel_attributes_values (tested in
# rails 3.2.13). the alternative is to build the entire insert statement using arel >_>
record.class.arel_table.create_insert \
.tap { |im| im.insert(record.send(:arel_attributes_values, false)) } \
.to_sql
@lankz
lankz / dependencies.rb
Last active December 15, 2015 23:49
Examples of monster functions from various Ruby codebases...
# length, structure of these methods make it difficult to mess with while preserving existing functionality
def const_missing(const_name, nesting = nil)
klass_name = name.presence || "Object"
unless nesting
# We'll assume that the nesting of Foo::Bar is ["Foo::Bar", "Foo"]
# even though it might not be, such as in the case of
# class Foo::Bar; Baz; end
nesting = []
<?php
$xml = <<<XML
<users>
<user>
<name>tim</name>
<email>tim@timland.com</email>
<password>plainpasswordsarebad</password>
</user>
</users>
@lankz
lankz / README.md
Last active December 12, 2015 09:39

SuperResources

SuperResources DRYs up your controller code by abstracting your controller's strandard RESTful actions and by providing standard helpers to access the controller's target resource(s) in a consistent way across all controllers. More than that, SuperResources exploits the application's routes to provide simplified path helpers for nested resources.

With SuperResources, in the great majority of common REST situations, you can use the same resource helpers and path helpers, regardless of the the specific type of resource or how it is nested, even if the resource is nested under many other resources.

Installation

gem list | cut -d" " -f1 | xargs gem uninstall -aIx
sed -i 's/[[:space:]]*$//'