Skip to content

Instantly share code, notes, and snippets.

View xprilion's full-sized avatar
:shipit:
Trying to work from home

Anubhav Singh xprilion

:shipit:
Trying to work from home
View GitHub Profile
@xprilion
xprilion / 1.js
Last active January 20, 2024 07:30
Firestore Rules
// Basic public access
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
@xprilion
xprilion / function.js
Created April 13, 2023 03:51
Here's a sample Node.js Cloud Function called processData that handles real-time data processing for inventory management. In this example, we assume that the inventory data is stored in a Firestore database and the Cloud Function is triggered by a Cloud Pub/Sub message containing the product ID and the change in quantity.
const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
const INVENTORY_COLLECTION = 'inventory';
async function updateInventory(productId, quantityChange) {
const productRef = firestore.collection(INVENTORY_COLLECTION).doc(productId);
try {
await firestore.runTransaction(async (transaction) => {
from django.contrib import admin
from .models import ModelName
class CustomModelAdmin(admin.ModelAdmin):
def __init__(self, model, admin_site):
self.list_display = [field.name for field in model._meta.fields]
super(CustomModelAdmin, self).__init__(model, admin_site)
@xprilion
xprilion / main.py
Created June 20, 2021 16:07
Change sample rate of wavefile without speeding up the audio
import librosa
import soundfile as sf
filepath = "sample.wav"
y, s = librosa.load(filepath, sr=16000)
sf.write(filepath, y, s)
@xprilion
xprilion / Python Websockets SSL with Let's Encrypt
Last active April 19, 2024 12:11
Python Websockets SSL with Lets Encrypt
## Python Websockets SSL with Lets Encrypt
This code uses the `python-websockets` library.
You'll need to generate the certificate and keyfile using Let's Encrypt.
After generating the files correctly, you need to make them accessible to the current user who runs the script, my way of doing this was to copy it to the home directory of the current user and change the owner to the current user, set the permissions of the files to 400.
To know more about this process, read the blog here - https://xprilion.com/python-websockets-ssl-with-lets-encrypt/
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context

Python Version

3.8

Date of Setup

13 Dec, 2019

PIP version

19.2.3

Install Virtualenv

def cm(cf):
tn = cf[0][0]
fp = cf[0][1]
fn = cf[1][0]
tp = cf[1][1]
print("TP: %d\nTN: %d" % (tp, tn))
print("FP: %d\nFN: %d" % (fp, fn))
[
{
"sepal_length": 5.1,
"sepal_width": 3.5,
"petal_length": 1.4,
"petal_width": 0.2,
"species": "setosa"
},
{
"sepal_length": 4.9,
@xprilion
xprilion / downloader.class.php
Last active March 18, 2018 06:28 — forked from psykzz/downloader.class.php
Simple rate limited downloader with example
<?php
/* *
* @filename downloader.class.php
* @author PsyKzz
* @edited_by xprilion
* @version 2.0.0
* @description Simple class to rate limit your downloads, while also providing a custom tickrate to combat timeout issues.
* @url http://www.psykzz.co.uk
* @url https://xprilion.com
*