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
jruby-1.7.4 :769 > Neo4j._query("start n=node(*) match (n) where n.username! =~ '(?i)chrISTOpher' return n").first[:n].username
=> "christopher"
u = Neo4j._query("start n=node(*) match (n) where n.subject! =~ '[a-z\s]+?at[a-z\s]+?' or n.username! =~ '[a-z]+?man[a-z]+?' return n").to_a
@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 / gist:caaa99727990cfd3e4b3
Last active April 10, 2016 08:51
jbuilder vs activemodel::serializers

Each one is original first, then OJ.

rake benchmarks:single_object_with_render:

#original

Calculating -------------------------------------
            jbuilder        30 i/100ms
active_model_serializers
@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