This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra/base' # this is 'modular' style | |
| require 'repository' | |
| class HelloWorld < Sinatra::Base | |
| def repository | |
| @repository ||= Repository.new | |
| end | |
| get '/*' do | |
| repository.get('foo') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| require 'rack/test' | |
| require 'hello_world' | |
| require 'repository' | |
| describe 'Hello World application' do | |
| include Rack::Test::Methods | |
| def app | |
| HelloWorld |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| grid :: [[Int]] | |
| grid = [[08,02,22,97,38,15,00,40,00,75,04,05,07,78,52,12,50,77,91,08], | |
| [49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,04,56,62,00], | |
| [81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,03,49,13,36,65], | |
| [52,70,95,23,04,60,11,42,69,24,68,56,01,32,56,71,37,02,36,91], | |
| [22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80], | |
| [24,47,32,60,99,03,45,02,44,75,33,53,78,36,84,20,35,17,12,50], | |
| [32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70], | |
| [67,26,20,68,02,62,12,20,95,63,94,39,63,08,40,91,66,49,94,21], | |
| [24,55,58,05,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.algoclass.dij | |
| import collection.immutable.IndexedSeq | |
| object Main { | |
| def readCityBlock(id: Int) = { | |
| val cityName = readLine() | |
| val neighbours = readLine().toInt | |
| val fromVertex = new Vertex(cityName, id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # So the problem is inserting data into neo using the batch API. So we have a bunch of people and we want to put them into the graph and also | |
| # add to to the index so that we can search for them. | |
| # The way the batch API works is that you can refer to previous commands by referencing their index in the list of commands (zero indexed) | |
| # e.g. if I want to reference the person added in the first command I would reference that node as {0} | |
| # You should be able to see how that works in the code below. | |
| neo_people_to_load = Set.new | |
| neo_people_to_load << { :name => "Mark Needham", :id => 1 } | |
| neo_people_to_load << { :name => "Jenn Smith", :id => 2 } | |
| neo_people_to_load << { :name => "Chris Ford", :id => 3 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Position = Position Int Int Direction | |
| deriving (Show, Eq, Read) | |
| data Direction = N | E | W | S | |
| deriving (Show, Eq, Enum, Bounded, Read) | |
| data Command = L | R | M | |
| deriving (Show, Eq, Enum, Bounded, Read) | |
| data DeltaPosition = DeltaPosition Int Int deriving (Show) | |
| data State = State { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'neography' | |
| start_time = Time.now | |
| puts "Start Time: #{start_time}" | |
| @neo = Neography::Rest.new(:port => 7476) | |
| all_the_people_query = "start n = node(*) where n.type? = 'person' and has(n.name) return n.name, id(n)" | |
| all_the_people = @neo.execute_query(all_the_people_query)["data"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| START n = node(*) | |
| MATCH n-[r:colleagues*1..2]->c, n-[r2:member_of]->office | |
| WHERE n.type? = 'person' and has(n.name) and (not(has(r2.end_date))) and office.name = 'London - UK South' and (not(has(c.thoughtquitter))) | |
| RETURN n.name, count(distinct(c)) AS connections, office.name | |
| ORDER BY connections DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ==> +------------------------------------+ | |
| ==> | office.name | COUNT(r) | | |
| ==> +------------------------------------+ | |
| ==> | "New York - US East" | 5 | | |
| ==> | "Chicago - US Central" | 1 | | |
| ==> | "Bangalore - India" | 2 | | |
| ==> | "Calgary - Canada West" | 3 | | |
| ==> | "London - UK South" | 31 | | |
| ==> | "ETG UK - ETG" | 1 | | |
| ==> | "Brisbane - Australia" | 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cypher: | |
| START researchArea = node:research_areas('research_area_id:1'), month = node:months('month:8'), year = node:years('year:2012') | |
| MATCH researchArea-[:has_child*1..5]->otherResearchArea-[:has_product]->product-[:sold]->sales-[:soldInMonth]->month, sales-[:soldInYear]->year | |
| RETURN DISTINCT(sales.sales), sales.name, product | |
| core API: | |
| GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase("/path/to/db"); |