Skip to content

Instantly share code, notes, and snippets.

@ryanpbrewster
ryanpbrewster / Cargo.toml
Last active June 5, 2019 07:37
faye-websocket client race condition issue
[package]
name = "helloworld"
version = "0.1.0"
authors = ["Ryan Brewster <ryanpbrewster@gmail.com>"]
edition = "2018"
[dependencies]
actix = "0.8.3"
actix-web = "1.0.0"
actix-web-actors = "1.0.0"
import java.net.URI
import java.util
import com.google.api.gax.core.FixedCredentialsProvider
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider
import com.google.auth.Credentials
import com.google.cloud.firestore.{CollectionReference, FirestoreOptions}
import com.google.common.collect.{ImmutableList, ImmutableMap}
import io.grpc.ManagedChannelBuilder
service cloud.firestore {
match /databases/{database}/documents {
function isValidRoomName(roomName, userId) {
return roomName.matches(".*" + userId + ".*");
}
match /users/{userId} {
allow read;
allow write: if isValidRoomName(request.resource.data.room[4], userId);
}
}
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read;
allow write: if exists(request.resource.data.room);
}
match /rooms/{roomId} {
allow read, write;
}
}
service cloud.firestore {
match /databases/{database}/documents {
function getUserData() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data
}
match /tenants/{tenantId} {
function isSignedIn() {
return request.auth != null;
}
function isUserInTenant(rsc) {
const firebase = require("@firebase/testing");
async function main() {
const projectId = "my-test-project";
await firebase.loadFirestoreRules({
projectId,
rules: `
service cloud.firestore {
match /databases/{database}/documents {
match /users/{company} {
@ryanpbrewster
ryanpbrewster / From word2vec to doc2vec: similarity driven CRP, by Yingjie Miao.py
Last active January 29, 2018 12:38
From word2vec to doc2vec --- similarity driven CRP by Yingjie Miao
# vecs: an array of real vectors
def crp(vecs):
clusterVec = [] # tracks sum of vectors in a cluster
clusterIdx = [] # array of index arrays. e.g. [[1, 3, 5], [2, 4, 6]]
ncluster = 0
# probablity to create a new table if new customer
# is not strongly "similar" to any existing table
pnew = 1.0/ (1 + ncluster)
N = len(vecs)
rands = random.rand(N) # N rand variables sampled from U(0, 1)
libraries["lDqTLC8xZQ8g"] = {
"id" : "lDqTLC8xZQ8g",
"name" : "The River Bend",
"description" : "A collection of water-related links",
"numKeeps" : 13,
"visibility": "published",
"slug": "the-river-bend",
"kind": "user_created",
"keeps" : [ "kIQFYKlZha6Q", "kBGiqTPuxJVT", "kzIPMrXS9S1a", "k8YKZMtEZ6nm", "k6kG2oFUqpEC", "k1hHZKtnTA8r", "kBZm7WHI0nvs", "k1jGnwdiFFhO", "k7OeeD7oknho", "k3ID5yZvNt9M", "k0CfhKj66BFn", "k442LEj9lhWw", "kBrFMEFdRAOs" ]
}
index = {
"me" : {
"id" : "180922ae-7aab-4622-b4ad-131e9c901fa6",
"firstName" : "Ryan",
"lastName" : "Brewster",
"pictureName" : "8qBhJ.jpg",
"username" : "ryanpbrewster"
},
"spaces" : [ {
"org" : {
keeps["k6LtZplP42BP"] = {
"id" : "k6LtZplP42BP",
"keptAt" : 1450124151000,
"lastActivityAt" : 1450136608000,
"title" : "BKS Iyengar - Google Search",
"url" : "https://www.google.com/search?q=BKS+Iyengar&oi=ddle&ct=bks-iyengars-97th-birthday-5749978756546560-hp&hl=en",
"note" : null,
"tags" : [ ],
"libraries" : [ "l4Ucs258jBwL" ],
"summary" : "Ramamani. Children. Geeta and 5 others. Bellur Krishnamachar Sundararaja Iyengar (14 December 1918 - 20 August 2014), better known as B.K.S. Iyengar, was the founder of the style of yoga known as \" Iyengar Yoga\" and was considered one of the foremost yoga teachers in the world.",