Skip to content

Instantly share code, notes, and snippets.

View bezysoftware's full-sized avatar

Tomas Bezouska bezysoftware

  • Step Up Labs, Inc.
  • Prague
View GitHub Profile
@bezysoftware
bezysoftware / firebaseRules.json
Last active January 3, 2017 13:49
Firebase rules
{
"rules": {
"users": {
"$user": {
".read": "auth.uid === $user",
".write": "auth.uid === $user"
}
}
}
}
var firebase = new FirebaseClient(
"https://dinosaur-facts.firebaseio.com/",
new FirebaseOptions
{
AuthTokenAsyncFactory = () => "token value"
});
var dinos = await firebase
.Child("dinosaurs")
.OnceAsync<Dinosaur>();
// authenticate user with facebook and use the access token
var token = "access_token_xyz";
// specify your app’s client key when creating the auth provider
var ap = new FirebaseAuthProvider(new FirebaseAuthConfig("<YOUR APP API KEY>"));
// sign in with OAuth. You can also sign in anonymously
var auth = ap.SignInWithOAuth(FirebaseAuthType.Facebook, token);
var firebase = new FirebaseClient(
// Get any Stream — it can be FileStream, MemoryStream or any other type of Stream
var stream = File.Open(@"C:\YourFile.png", FileMode.Open);
// Construct FirebaseStorage with path to where you want to upload the file and put it there
var task = new FirebaseStorage("your-bucket.appspot.com")
 .Child("data")
 .Child("random")
 .Child("file.png")
 .PutAsync(stream);
@bezysoftware
bezysoftware / Changes.ts
Last active March 17, 2017 09:11
Changes cloud function
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { Event } from 'firebase-functions';
import { DeltaSnapshot } from 'firebase-functions/lib/providers/database';
// intialize admin
admin.initializeApp(functions.config().firebase);
// export the function registration
export let writeTransactionChange = functions
@bezysoftware
bezysoftware / RegistrationStructure.json
Created March 13, 2017 09:30
Sample of Settle Up's database for FCM registrations
{
"pushRegistrations": {
"uid_1": {
"push_token_1": {
"platform": "android"
}
}
}
function createRawPayload(userName: string, groupName: string, groupId: string, change: Change)
{
let payload =
{
data:
{
"by" : userName,
"action" : change.action,
"entity" : change.entity,
"groupId" : groupId,
// refresh currency rates
export let refreshExchangeRates = functions
.https
.onRequest(async (request, response) =>
{
await refreshExchangeRates();
response.end();
});
// functions to pull latest exchange rates and store them
// change group currency task registration
export let changeGroupCurrency = functions
.database
.ref('/serverTasks/currencyChange/{taskId}')
.onWrite(event => changeGroupCurrency(event));
// function which changes group's currency and updates exchange rates of all expenses
async function changeGroupCurrency(event: Event<DeltaSnapshot>)
{
// prevent triggering this function after writing response code
{
"serverTasks": {
"currencyChange" : {
"task_id_3": {
"serverTimestamp": 21312321321,
"request": {
"groupId": "group_id_1",
"targetCurrency": "CZK"
},
"response": {