Skip to content

Instantly share code, notes, and snippets.

View sararob's full-sized avatar

Sara Robinson sararob

  • Firebase
  • San Francisco, CA
View GitHub Profile
@sararob
sararob / hn-api-examples.md
Last active August 29, 2015 14:07
Apps & integrations built with the official HN API

Integrations

Apps

Angular

@sararob
sararob / upvote-security-rules.json
Created August 25, 2015 17:25
Upvoting example for Firebase security rules
{
"rules": {
".read": true,
"articles": {
"$article": {
"title": {
".write": "auth != null",
".validate": "newData.isString() && newData.val() != ''"
},
"url": {
@sararob
sararob / count-adjectives.sql
Last active November 20, 2016 21:55
Count all adjectives in tweets about Hillary and Trump in BigQuery
SELECT
COUNT(*) as c, adjective, subject
FROM
JS(
(SELECT tokens FROM [sara-bigquery:syntax.election_tweets]),
tokens,
"[{ name: 'adjective', type: 'string'},
{name: 'subject', type: 'string'}
]",
"function(row, emit) {
import * as tf from ‘@tensorflow/tfjs’;
const model = tf.sequential();
model.add(tf.layers.dense({inputShape: [4], units: 100}));
model.add(tf.layers.dense({units: 4}));
model.compile({loss: ‘categoricalCrossentropy’, optimizer: ‘sgd’});
await model.fit(
xData, yData, {
batchSize: batchSize,
epochs: epochs
});
@sararob
sararob / app.js
Created September 28, 2014 21:07
Example of implementing a hasMany / belongsTo relationship in EmberFire
var App = Ember.Application.create({});
var Promise = Ember.RSVP.Promise;
// ADAPTER
App.ApplicationAdapter = DS.FirebaseAdapter.extend({
firebase: new Firebase("https://<your-firebase-name>.firebaseio.com/")
});
@sararob
sararob / bike-query.sql
Last active August 12, 2019 21:47
The life of Citibike # 17526
# Enable Standard SQL to run this query
# More on BigQuery here: https://cloud.google.com/bigquery/docs/quickstarts
SELECT
REGEXP_REPLACE(starttime, '([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})', '\\3-\\1-\\2') as starttime,
from_station_lat,
from_station_lng
FROM `sara-bigquery.nyc_citibike.trips_*`
WHERE cast(bikeid as int64) = 17526 # This is the bike with the most trips (found from another query)
order by starttime
@sararob
sararob / speech-api-request.sh
Last active August 12, 2019 21:48
Bash script for recording audio and calling the Cloud Speech API
#!/bin/bash
# SETUP
# 1) This requires having SoX (http://sox.sourceforge.net/) installed. On a Mac, you can do this with `brew install sox --with-flac`
# 2) You'll also need an API key for your Google Cloud Platform project: https://support.google.com/cloud/answer/6158862
# Create a request file with our JSON request in the current directory
FILENAME="request-"`date +"%s".json`
cat <<EOF > $FILENAME
{
@sararob
sararob / cloud-nlp.js
Created April 19, 2017 15:20
Call the Cloud Natural Language API from Node.js
'use strict';
const fs = require('fs');
const ndjson = require('ndjson');
const request = require('request');
fs.createReadStream('reddit-comments.json') // Newline delimited JSON file
.pipe(ndjson.parse())
.on('data', function(obj) {
// Get measurements for a new flower to generate a prediction
// The first argument is the data, and the second is the shape.
const inputData = tf.tensor2d([[4.8, 3.0, 1.4, 0.1]], [1, 4]);
// Get the highest confidence prediction from our model
const result = model.predict(inputData);
const winner = irisClasses[result.argMax().dataSync()[0]];
// Display the winner
console.log(winner);