Skip to content

Instantly share code, notes, and snippets.

View subvertallchris's full-sized avatar
💭
🤘 brutal

Chris Grigg subvertallchris

💭
🤘 brutal
  • Long Island City, NY
View GitHub Profile
@subvertallchris
subvertallchris / dumb_has_many_example.rb
Last active August 29, 2015 14:04
really simple example of has_many behavior
#copy and paste into rails console to play
module DumbHasMany
extend ActiveSupport::Concern
module ClassMethods
def has_many(method, args=nil)
if args.nil? || !args.is_a?(Hash)
type = method
else
@subvertallchris
subvertallchris / neo4jrb-demo.rb
Created September 5, 2014 14:12
showing off some of the basics of neo4j.rb 3
[Student, Lesson, Teacher, Exam].each{|c| c.destroy_all }
ss101 = Lesson.create(subject: 'Social Studies', level: 101)
ss102 = Lesson.create(subject: 'Social Studies', level: 102)
math101 = Lesson.create(subject: 'Math', level: 101)
math201 = Lesson.create(subject: 'Math', level: 201)
geo103 = Lesson.create(subject: 'Geography', level: 103)
sandra = Student.create(name: 'Sandra', age: 16)
danny = Student.create(name: 'Danny', age: 15)
@subvertallchris
subvertallchris / my_inject.rb
Last active August 29, 2015 14:06
my_inject refactored for /u/zaclacgit
def my_inject(initial = nil, sym = nil)
memo, starter = initial, self if initial && block_given?
memo, starter = self[0], self[1..-1] if initial.nil? || !block_given?
starter.push(initial) unless sym.nil? || block_given?
starter.my_each do |x|
if sym
memo = memo.send(sym, x)
elsif block_given?
memo = yield(memo,x)
else
ORIGINAL
2.1.2 :002 > Benchmark.ips do |x|
2.1.2 :003 > x.config(:time => 5, :warmup => 2)
2.1.2 :004?> x.time = 10
2.1.2 :005?> x.warmup = 2
2.1.2 :006?> x.report("query") { Student.limit(900).each { |s| } }
2.1.2 :007?> end
Calculating -------------------------------------
query CYPHER 26ms MATCH (result:`Student`) RETURN result LIMIT 900
# /u/zaclacgit on Reddit posted a topic the other day asking for thoughts on his exercise of
# recreating some basic enumerable methods. I gave him some tips on refactoring one method in particular
# and a few days later, he asked me to elaborate. I thought the easiest way might be to go through each
# step of the refactor and I'd get a nice blog post out of it in the process.
# To use this, start by commenting out each `my_inject` definition except the first. As you encounter
# new ones, uncomment them. Save this file as `refactor.rb` in the folder of your choice, ensure you have
# the rspec gem installed and run `rspec refactor.rb` from CLI to execute.
# Before we write a line of code, we're going to write specs based off of the simple comparisons
[
{
"columns": [
"r"
],
"data": [
{
"row": [
{
"_classname": "StudentLesson"
@subvertallchris
subvertallchris / models.rb
Created September 30, 2014 00:15
movies models?
class Movie
include Neo4j::ActiveNode
id_property :title
has_many :in, :actors, model_class: :Person, rel_class: Engagement
end
class Engagement
include Neo4j::ActiveRel
from_class Person
to_class Movie
@subvertallchris
subvertallchris / return_test.rb
Created November 26, 2014 02:04
Testing implicit VS explicit returns
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(warmup: 1, time: 5)
def test1
a = [:foo, :bar, :baz, :omg, :wtf, :gtfo]
a.map(&:to_s)
end
@subvertallchris
subvertallchris / Post.rb
Last active August 29, 2015 14:10 — forked from Jberczel/Post.rb
class Post < ActiveRecord::Base
extend AgfScrape
default_scope { order(:id) }
def self.url
"http://www.acousticguitarforum.com/forums/forumdisplay.php"\
"?f=17&pp=200&sort=lastpost&order=desc&daysprune=200"
end
def self.forum
2015-02-02 15:19:27.559+0000 INFO [o.n.s.CommunityNeoServer]: Setting startup timeout to: 120000ms based on 120000
2015-02-02 15:19:27.671+0000 INFO [o.n.k.InternalAbstractGraphDatabase]: No locking implementation specified, defaulting to 'community'
2015-02-02 15:19:27.776+0000 INFO [o.n.k.i.DiagnosticsManager]: --- INITIALIZED diagnostics START ---
2015-02-02 15:19:27.778+0000 INFO [o.n.k.i.DiagnosticsManager]: Neo4j Kernel properties:
2015-02-02 15:19:27.783+0000 INFO [o.n.k.i.DiagnosticsManager]: store_dir=/Users/cgrigg/RailsCrap/neotest/db/neo4j/development/data/graph.db
2015-02-02 15:19:27.783+0000 INFO [o.n.k.i.DiagnosticsManager]: remote_shell_enabled=true
2015-02-02 15:19:27.784+0000 INFO [o.n.k.i.DiagnosticsManager]: Diagnostics providers:
2015-02-02 15:19:27.784+0000 INFO [o.n.k.i.DiagnosticsManager]: org.neo4j.kernel.configuration.Config
2015-02-02 15:19:27.784+0000 INFO [o.n.k.i.DiagnosticsManager]: org.neo4j.kernel.info.DiagnosticsManager
2015-02-02 15:19:27.784+0000 INFO [o.n.k.i.Diag