Skip to content

Instantly share code, notes, and snippets.

View andreasronge's full-sized avatar

Andreas Ronge andreasronge

View GitHub Profile
defmodule Game do
defstruct board: nil, my_position: nil, name: "", health: 0
end
defmodule Board do
defstruct positions: %{}, width: 0, height: 0
end
defmodule Snake do
defstruct id: "", positions: %{}
class TransactionalExec
attr_accessor :commit_every, :block
def initialize(commit_every, max_lines = nil, verbose = true, &block)
@commit_every = commit_every
@block = block
@max_lines = max_lines
@verbose = verbose
end
@andreasronge
andreasronge / neo4j.rb
Created July 6, 2013 09:47
Spike on neo4j 2.0 featrues
require 'java'
require 'forwardable'
require 'fileutils'
# Load Neo4j Jars for the jars folder
# Put the neo4j 2.0 jars there
jar_folder = File.expand_path('../jars', __FILE__)
jars = Dir.new(jar_folder).entries.find_all { |x| x =~ /\.jar$/ }
jars.each { |jar| require File.expand_path(jar, jar_folder) }
@andreasronge
andreasronge / show.rb
Created April 22, 2013 07:34
Working with relstionships
require 'neo4j'
class Show < Neo4j::Rails::Model
property :show_name, type: String, index: :exact
has_n :booked_bands
end
#I have another model, band.rb
class Band < Neo4j::Rails::Model
@andreasronge
andreasronge / Gemfile
Last active December 10, 2015 08:28
Complete Ha Example
source 'https://rubygems.org'
gem 'rails', '3.2.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'jruby-openssl'
@andreasronge
andreasronge / README.md
Last active October 27, 2015 18:44
Trying to improve redux architecture - cohesion and state context

Redux-Context

Notice No implementation exist yet, see Readme Driven Development

The problem:

  • Bad cohesion - in a typical redux application it's difficult to understand how it works since it consists of many small (good !) related functions spread out in many different files and folders.
  • Bad isolation - many functions (redux's actions and react-redux's connect) uses the global redux state object. Only reducers works on subtrees of the state tree.
  • Too many level of indirections - React props referencing redux state via mapStateToProps functions, reducers references actions via strings, async action creators references redux state.
me = lookup('node_auto_index', 'name', "Joe").as(:me)
me > rel(:favorite) > node(:myFavorites) > rel(:tagged) > node(:tag) < rel(:tagged) < node(:theirFavorites) < rel(:favorite) < node(:people)
me != node(:people)
ret node(:people)[:name].as(:name), count.desc.as(:similar_favs)
@andreasronge
andreasronge / StackTrace
Created August 17, 2012 10:16
JVM Crash using JRuby 1.7.preview2
Environment
===========
Mac OSX
jruby 1.7.0.preview2
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
How to Reproduce
require 'rubygems'
require 'neo4j-core'
def connect(d)
d.each{|i| Neo4j::Relationship.new(:flies_to, i[:from], i[:to])}
end
tx = Neo4j::Transaction.new
@a, @b, @c, @z = %w[A B C D].map{|name| Neo4j::Node.new(:name => name)}
connect([ {:from=>@a, :to=>@b}, {:from=>@a, :to=>@c}, {:from=>@b, :to=>@c},
@andreasronge
andreasronge / basic_test.rb
Created January 5, 2012 13:42
Domain Example
# load 'nodes.rb'
require 'rubygems'
require 'neo4j'
alice = Neo4j::Transaction.run { Neo4j::Node.new }
bob = Neo4j::Transaction.run { Neo4j::Node.new }
Neo4j::Transaction.run do
alice[:name] = "alice"
alice[:score] = [42,4]