Skip to content

Instantly share code, notes, and snippets.

View puf's full-sized avatar

Frank van Puffelen puf

View GitHub Profile
@puf
puf / Unzip from LINQPad
Last active April 19, 2024 16:31
LINQPad script to unzip all files under a given directory
// This LINQPad script (easily converted into a regular C# program) extracts all zip files under a specific directory.
// makes use of the ZipUtility from http://linqpadsamples.codeplex.com/wikipage?title=Unzip%20a%20file%20using%20COM%20and%20dynamic
var files = Directory.EnumerateFiles(@"C:\Test Data\Gutenberg\pgdvd042010", "*.zip", SearchOption.AllDirectories).ToArray();
var dc = new DumpContainer().Dump();
var index=0;
var count=files.Count();
foreach (var file in files) {
dc.Content = string.Format("{0}/{1}: {2}", index++, count, file);
@puf
puf / README.md
Last active March 28, 2023 16:37
Firebase Hosting Deploy Single File

This script may no longer work. Have a look at its (more official) replacement: https://github.com/firebase/firebase-tools/tree/master/scripts/examples/hosting/update-single-file

Firebase Hosting Deploy Single File

This utility script deploy a single local file to an existing Firebase Hosting site. Other files that are already deployed are left unmodified.

The difference with firebase deploy is that this script does not require you to have a local snapshot of all hosted files, you just need the one file that you want to add/update.

@puf
puf / index.html
Last active January 15, 2023 19:41
Zero to App: Develop with Firebase (for Web - Google I/O 2016)
<html>
<head>
<script src="https://www.gstatic.com/firebasejs/3.0.0/firebase.js"></script>
<title>ZeroToApp</title>
<style>
#messages { width: 40em; border: 1px solid grey; min-height: 20em; }
#messages img { max-width: 240px; max-height: 160px; display: block; }
#header { position: fixed; top: 0; background-color: white; }
.push { margin-bottom: 2em; }
@keyframes yellow-fade { 0% {background: #f2f2b8;} 100% {background: none;} }
@puf
puf / ChatMessage.java
Last active July 12, 2021 21:56
Zero to App: Develop with Firebase (for Android - Google I/O 2016)
package com.google.firebase.zerotoapp;
public class ChatMessage {
public String name;
public String message;
public ChatMessage() {
}
public ChatMessage(String name, String message) {
@puf
puf / Listen for authentication state.java
Created January 5, 2021 23:35
Listen for authentication state in Android
// In Firebase it is often better to *react* to authentication state
// changes, instead getting the current authentication state everywhere.
// To respond to auth state changes, use an auth state change listener
// like this:
FirebaseAuth auth = FirebaseAuth.getInstance();
auth.addAuthStateListener(new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() == null) {
Log.i("firebase", "AuthState changed to null");
@puf
puf / Detect write errors in Firebase Realtime Database in Android.java
Last active January 5, 2021 23:02
Detect write errors in Firebase Realtime Database in Android
// To detect when a write operation is rejected by your Realtime Database
// security rules, add a completion listener to the `setValue()` call and
// throw the exception if the task failed.
val ref = FirebaseDatabase.getInstance().getReference()
ref.push()
.setValue(ServerValue.TIMESTAMP)
.addOnCompleteListener(new CompletionListener() {
@Override
public void onComplete(Task<Void> task) {
Log.i("firebase", String.valueOf(task.isSuccessful()))
@puf
puf / WaitForInitialValue.java
Last active March 3, 2018 18:27
Waiting for an initial value
public class Main {
static ValueEventListener mListener;
public static void main(String[] args) throws Exception {
Firebase ref = new Firebase("https://<your-app>.firebaseio.com/");
mListener = ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
System.out.println("The value is now "+snapshot.getValue());
@puf
puf / Profiler.cs
Last active July 17, 2017 16:29
Tiny C# "manual" profiler (for those days that your proper profiler is proving too difficult to work with)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
public static class Profiler {
private static List<ProfilerFrame> stack = new List<ProfilerFrame>();
private static Dictionary<string, ProfiledBlock> totals = new Dictionary<string, ProfiledBlock>();
private static Action<string> logger;
@puf
puf / index.android.js
Created December 14, 2015 17:51
Simple example of a React Native chat app for Android (using Firebase)
'use strict';
var React = require('react-native');
var Firebase = require('firebase');
var {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
@puf
puf / acknowledge.js
Created January 26, 2016 00:58
Account merging
var ref = new Firebase('https://yours.firebaseio.com/acknowledge');
var users = [];
function $(selector) {
var result = document.querySelectorAll(selector);
return (result.length > 1) ? Array.prototype.slice.call(result) : result[0];
}
function handleAuthResult(error, authData) {
if (error) {