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
| export const onAnswer = functions.firestore.document('/pic/{picId}').onUpdate(_onAnswer) | |
| async function _onAnswer(change: functions.Change<DocumentSnapshot>): Promise<any> { | |
| const picId = change.before.id "//20180624120000" | |
| const previous = change.before.data() as Pic | |
| const pic = change.after.data() as Pic | |
| // Only interested in pics that have a new answer | |
| if (previous.answer || !pic.answer) { | |
| console.log("This is not the update you are looking for.") | |
| return Promise.resolve() |
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
| const payload = { | |
| data: { | |
| disposition: pic.answer.disposition.toString(), | |
| pic_id: picId | |
| } | |
| } | |
| try { | |
| const response = await fcm.sendToTopic('answers',payload) |
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
| findViewById<Button>(R.id.btn_sign_in).setOnClickListener { | |
| startActivityForResult( | |
| AuthUI.getInstance() | |
| .createSignInIntentBuilder() | |
| .setAvailableProviders(listOf(AuthUI.IdpConfig.GoogleBuilder().build())) | |
| .build(), | |
| RC_SIGN_IN | |
| ) | |
| } |
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
| override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { | |
| super.onActivityResult(requestCode, resultCode, data) | |
| if (requestCode == RC_SIGN_IN) { | |
| val response = IdpResponse.fromResultIntent(data) | |
| if (resultCode == Activity.RESULT_OK) { | |
| // handle login | |
| } | |
| } | |
| } |
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
| private fun trySignIn() { | |
| Log.d(TAG, "Signing in with tocken" + tocken) | |
| val credential = GoogleAuthProvider.getCredential(token, null) | |
| FirebaseAuth.getInstance().signInWithCredential(credential) | |
| .addOnSuccessListener(this, { result -> | |
| val user = result.user | |
| Log.d(TAG, "signInWithCredential ${user.displayName} ${user.email}") | |
| finish() | |
| }) | |
| .addOnFailureListener(this, { e -> |
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
| exports = async function (payload) { | |
| const mongodb = context.services.get("mongodb-atlas"); | |
| const exampledb = mongodb.db("exampledb"); | |
| const examplecoll = exampledb.collection("examplecoll"); | |
| const args = payload.query.text.split(" "); | |
| switch (args[0]) { | |
| case "stash": | |
| const result = await examplecoll.insertOne({ |
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
| X = tf.placeholder(tf.float32, shape=[None, n_inputs]) | |
| weights1_init = initializer([n_inputs, n_hidden1]) | |
| weights2_init = initializer([n_hidden1, n_hidden2]) | |
| weights1 = tf.Variable(weights1_init, dtype=tf.float32, name="weights1") | |
| weights2 = tf.Variable(weights2_init, dtype=tf.float32, name="weights2") | |
| weights3 = tf.transpose(weights2, name="weights3") # tied weights | |
| weights4 = tf.transpose(weights1, name="weights4") # tied weights |
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
| def train_autoencoder(X_train, n_neurons, n_epochs, batch_size, | |
| learning_rate = 0.01, l2_reg = 0.0005, seed=42, | |
| hidden_activation=tf.nn.elu, | |
| output_activation=tf.nn.elu): | |
| graph = tf.Graph() | |
| with graph.as_default(): | |
| tf.set_random_seed(seed) | |
| n_inputs = X_train.shape[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
| # first phase of AE, trained on the training data | |
| hidden_output, W1, b1, W4, b4 = train_autoencoder(mnist.train.images, n_neurons=300, n_epochs=4, batch_size=150, | |
| # second phase of AE, trained on the previous Autoencoder's hidden layer output | |
| _, W2, b2, W3, b3 = train_autoencoder(hidden_output, n_neurons=150, n_epochs=4, batch_size=150) |
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
| # image input | |
| n_inputs = 28*28 | |
| # merged to one stacked AE | |
| X = tf.placeholder(tf.float32, shape=[None, n_inputs]) | |
| hidden1 = tf.nn.elu(tf.matmul(X, W1) + b1) | |
| hidden2 = tf.nn.elu(tf.matmul(hidden1, W2) + b2) | |
| hidden3 = tf.nn.elu(tf.matmul(hidden2, W3) + b3) | |
| outputs = tf.matmul(hidden3, W4) + b4 |