Skip to content

Instantly share code, notes, and snippets.

@benixal
benixal / worker.js
Last active February 11, 2025 10:16
Free Telegram Upload Center
/*
https://github.com/benixal
https://www.youtube.com/@benixal
*/
export default {
// @ts-ignore
async fetch(request, env, ctx) {
@benixal
benixal / index.html
Created February 9, 2024 19:54
WebSocket HTML Chat Client and Server
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket Simple Chat</title>
<style>
#chatbox {
@benixal
benixal / firebase-messaging-sw.js
Last active March 25, 2024 09:39
Firebase Cloud Messaging (FCM) custom service worker
self.addEventListener("push", (event) => {
const notif = event.data.json().notification;
event.waitUntil(self.registration.showNotification(notif.title, {
body: notif.body,
icon: notif.image, /* or "icon.png" */
data: {
url: notif.click_action
}
}))
})
@benixal
benixal / php-fcm-send.php
Created September 22, 2023 10:10
PHP code snippet for sending a Firebase Cloud Messaging (FCM) notification
<?php
$authorizationHeader = "Authorization: Bearer <YOUR_ACCESS_TOKEN>";
/*
Steps to get Authentication Bearer :
1.Got to Google OAuth Playground: https://developers.google.com/oauthplayground
2.In the "Input your own scopes" for FCM use this url: https://www.googleapis.com/auth/firebase.messaging
3.Tap Authorize API.
4.Pick correct user for authorisation and allow access.
@benixal
benixal / fcm-push-admin.js
Created February 25, 2023 04:23
firebase cloud messaging admin send push notification
// full project with vue: https://github.com/benixal/vue-firebase-push-notification
var admin = require("firebase-admin");
var serviceAccount = require("./your-private-key.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
// This registration token comes from the client FCM SDKs.
@benixal
benixal / simpleAPI.js
Last active February 4, 2023 20:27
a simple API server with GET , POST , PUT , PATCH , DELETE methods
const http = require('http');
var fs = require('fs');
const port = 8060;
var db = "database";
if (!fs.existsSync(db)) {
fs.mkdirSync(db);
}
@benixal
benixal / firestoreRule.txt
Last active December 22, 2022 14:56
firestore rule : allow read, write only admin
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /chats/{userId}/{document=**} {
allow read, write: if
(
userId == request.auth.uid
@benixal
benixal / apiServer.js
Created December 11, 2022 14:10
simple nodejs api test
const http = require('http');
const port = 8089;
http.createServer((req, res) => {
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': '*',
'Access-Control-Request-Method': '*',
'Access-Control-Allow-Headers': '*',