This file contains 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
// link two vertices, if the link does not already exists | |
// return the new or the existing link / edge | |
Gremlin.defineStep('link', [Vertex,Pipe], { direction, label, other -> | |
exists = false | |
dirs = direction.toString() | |
dir = dirs.toLowerCase() | |
edge = dir + "E" | |
oppV = direction.opposite().toString().toLowerCase() + "V" | |
link = "link" + dirs.substring(0,1) + dir.substring(1) | |
_()."$dir"(label).filter{it==other}.sideEffect{exists=true}.optional(3).ifThenElse{exists} \ |
This file contains 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
# | |
# First: Start a new m1.large EC2 instance with Amazon Linux AMI | |
# Next: Copy/Paste all the following code | |
# | |
wget http://www.grouplens.org/sites/www.grouplens.org/external_files/data/ml-10m.zip | |
unzip ml-10m.zip | |
cp ml-10M100K/*.dat /tmp | |
rm -f ml-10m.zip | |
rm -rf ml-10M100K/ |
This file contains 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
module RedisHelper | |
# decode Redis value back to Ruby object | |
def self.decode(json) | |
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"]) | |
end | |
# encode Ruby object for Redis | |
def encoded | |
self.updated_at = nil | |
self.to_json |
This file contains 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
# ------------------------------------------------------------------ | |
# Desigining "trending topics in 24 hours sliding window" with Redis | |
# ------------------------------------------------------------------ | |
redis-cli del tophashes:2010-12-07-08-00 | |
redis-cli del tophashes:2010-12-07-09-00 | |
redis-cli del tophashes:current | |
echo '=== 8:00 AM ===' |
This file contains 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
import bisect | |
class NFA(object): | |
EPSILON = object() | |
ANY = object() | |
def __init__(self, start_state): | |
self.transitions = {} | |
self.final_states = set() | |
self._start_state = start_state |