Skip to content

Instantly share code, notes, and snippets.

View DennisAlund's full-sized avatar
💭
ngoding

Dennis Alund DennisAlund

💭
ngoding
View GitHub Profile
unit_test:
stage: test
only:
- develop
- master
before_script:
- export ANDROID_HOME=$PWD/.android
- export PATH=$PATH:$PWD/.android/platform-tools/
.build_template: &build_template_def
stage: build
artifacts:
expire_in: 4 hours
paths:
- app/build/outputs/
- .android/
before_script:
# Extract the SDK version that we're building against
@DennisAlund
DennisAlund / sendPingPongScore.ts
Created April 5, 2017 05:11
Firebase cloud function for Slack button actions in medium article https://medium.com/evenbit/151c1c98641d
async function sendPingPongScore(pingId: string) {
const payload = {attachments: []};
const ping = (await admin.database().ref("ping").child(pingId).once("value")).val();
const snap = await admin.database().ref("pong").orderByChild("ping").equalTo(pingId).limitToFirst(3).once("value");
const medalColors = ["#C98910", "#A8A8A8", "#965A38"];
let counter = 0;
snap.forEach((childSnap) => {
const pong = childSnap.val() as Pong;
const color = medalColors[counter];
@DennisAlund
DennisAlund / database_trigger.ts
Created April 5, 2017 04:52
Firebase cloud function for Slack button actions in medium article https://medium.com/evenbit/151c1c98641d
export const on_actions = functions.database.ref("actions/{id}").onWrite(async (event) => {
if (!event.data.exists()) {
return "Nothing to do for deletion of processed commands.";
}
// Start by deleting the action request itself from the queue
await event.data.ref.remove();
const action = event.data.val();
@DennisAlund
DennisAlund / http_trigger.ts
Last active April 5, 2017 06:24
Firebase cloud function for Slack button actions in medium article https://medium.com/evenbit/151c1c98641d
export const message_action = functions.https.onRequest(async (request, response) => {
if (request.method !== "POST") {
console.error(`Got unsupported ${request.method} request. Expected POST.`);
return response.send(405, "Only POST requests are accepted");
}
if (!request.body && request.body.payload) {
return response.send(405, "Expected a message action payload.");
}
@DennisAlund
DennisAlund / database_trigger.ts
Created April 5, 2017 04:28
Firebase cloud function for Slack slash command in medium article https://medium.com/evenbit/151c1c98641d
export const on_command_ping = functions.database.ref("commands/ping/{id}").onWrite(async (event) => {
if (!event.data.exists()) {
return "Nothing to do for deletion of processed commands.";
}
// Start by deleting the command itself from the queue
await event.data.ref.remove();
const command = event.data.val();
@DennisAlund
DennisAlund / oauth.ts
Last active October 21, 2018 15:15
Firebase cloud function for OAuth handshake in medium article https://medium.com/evenbit/151c1c98641d
export const oauth_redirect = functions.https.onRequest(async (request, response) => {
if (request.method !== "GET") {
console.error(`Got unsupported ${request.method} request. Expected GET.`);
return response.send(405, "Only GET requests are accepted");
}
if (!request.query && !request.query.code) {
return response.status(401).send("Missing query attribute 'code'");
}
{
"ok": true,
"access_token": "xoxp-111111111111-222222222222-333333333333-abcdef0123456789",
"scope": "identify,commands,incoming-webhook",
"user_id": "U11MAYA11",
"team_name": "oddbit",
"team_id": "T22SARA22",
"incoming_webhook": {
"channel": "#random",
"channel_id": "C03ALUND3",
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /cron
script: main.app
login: admin
env_variables:
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp(functions.config().firebase);
export const onCreated = functions.database.ref("timings/{id}/created").onWrite(event => {
return event.data.ref.parent.child("handled").set(admin.database.ServerValue.TIMESTAMP);
});
export const onHandled = functions.database.ref("timings/{id}").onWrite(async event => {