Skip to content

Instantly share code, notes, and snippets.

View wonsuc's full-sized avatar

Jason Yoo (Wonsuc Yoo) wonsuc

  • pwdr
  • Seoul, South Korea
View GitHub Profile
@leblancmeneses
leblancmeneses / bolt-rules-throttle.json
Last active April 4, 2017 13:23 — forked from katowulf/rules.json
throttle messages to no more than one every 5,000 milliseconds, see http://jsfiddle.net/firebase/VBmA5/
type SharedWithInviteRequest {
........
createdDate: RateLimiting
}
// in order to write a message, I must first make an entry in users/${uid}/rate_limiting/{feature} is Number
// additionally, that message must be within 500ms of now, which means I can't
// just re-use the same one over and over, thus, we've effectively required messages
// to be 5 seconds apart
type RateLimiting extends Number {
@achudars
achudars / web-snippet-055 ( upload to Imgur in JavaScript)
Created August 12, 2013 08:31
Use JavaScript to upload anonymously to Imgur using Imgur API and show the link to the file. Make sure your API key is valid and working!
function upload(file) {
var imageLink ="";
/* Is the file an image? */
if (!file || !file.type.match(/image.*/)) return;
var fd = new FormData();
fd.append("image", file); // Append the file
fd.append("key", "<Imgur API key>");
@Atrix1987
Atrix1987 / firebase_function_feed.js
Created April 23, 2017 09:19
Firebase Function snippet for populating a user feed
exports.updateFeed = functions.database.ref('/stories/{userId}/{storyId}').onWrite(event => {
const userId = event.params.userId;
const storyId = event.params.storyId;
let followersRef = admin.database().ref('/followers/'+userId);
if(!event.data.val()){
//post was deleted
followersRef.once("value", function(snap) {
snap.forEach(function(childSnapshot) {
let followerId = childSnapshot.key;
@jthegedus
jthegedus / CF4F-express|functionsES6|index-03.js
Last active March 4, 2019 06:32
Cloud Functions for Firebase - Express example 3/3 - using CORS and automatically appending a trailing slash
const functions = require("firebase-functions")
const cors = require("cors")
const express = require("express")
/* Express with CORS & automatic trailing '/' solution */
const app3 = express()
app3.use(cors({ origin: true }))
app3.get("*", (request, response) => {
response.send(
"Hello from Express on Firebase with CORS! No trailing '/' required!"
@aows
aows / gist:0bdd2ead2fb2ed1d4872
Created May 27, 2015 00:10
Changing text color of a MenuItem programmatically (Android)
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem settingsMenuItem = menu.findItem(R.id.action_settings);
SpannableString s = new SpannableString(settingsMenuItem.getTitle());
s.setSpan(new ForegroundColorSpan(yourColor), 0, s.length(), 0);
settingsMenuItem.setTitle(s);
return super.onPrepareOptionsMenu(menu);
}
@laoyur
laoyur / BaseActivity.java
Last active October 23, 2019 13:40
hide keyboard on touching outside of EditText.
//author: laoyur
//inspired of http://stackoverflow.com/a/31021154
package com.laoyur.test;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
@somecuitears
somecuitears / Gradle SpringMVC.md
Last active January 27, 2020 16:05
Spring MVC from Gradle in IntelliJ

Creating Gradle Project

  1. Create New Project

  2. Select Java and Web from the Option

  3. You will be asked to provide GroupID and ArtifactID

  • GroupID: it will identify your project uniquely across all projects. (E.g. com.project.model | com.project.plugins)
@JoeRoddy
JoeRoddy / FirebaseToFirestore.js
Created October 18, 2017 16:19
Convert Firebase Database JSON to Firestore Collections
var db = firebase.firestore();
var content = require("./sourceData.json");
content &&
Object.keys(content).forEach(contentKey => {
const nestedContent = content[contentKey];
if (typeof nestedContent === "object") {
Object.keys(nestedContent).forEach(docTitle => {
firebase
.firestore()
import androidx.compose.animation.animatedFloat
import androidx.compose.animation.core.AnimationConstants
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.repeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.onActive
import androidx.compose.ui.Modifier
@acorn1010
acorn1010 / FirestoreUtils.ts
Created May 16, 2021 11:28
Hacky Firestore onWrite without slow initialization.
const service = 'firestore.googleapis.com';
// Note: We avoid importing firebase-functions because we don't want to slow down startup times.
type Change<T> = any;
type DocumentSnapshot = any;
type EventContext = any;
type CloudFunction<T> = any;
/**
* Creates an onWrite function for use as a Firestore onWrite callback. Replaces functions.firestore.document().onWrite().
* @param projectId the Firebase project id for the entire project (e.g. "foo-123").
* @param path a Firestore path such as "usernames/{username}"