Skip to content

Instantly share code, notes, and snippets.

View alfredfrancis's full-sized avatar
🎯
Focusing

Alfred Francis alfredfrancis

🎯
Focusing
View GitHub Profile
@alfredfrancis
alfredfrancis / remove_email_signature.py
Created September 30, 2020 15:08
Python script to remove email signature
import talon
from talon import quotations
from talon.signature.bruteforce import extract_signature
import html2text
raw_text = '<div dir="ltr"><div>\n<span style="color:rgb(0,0,0);font-family:docs-Calibri;font-size:15px;white-space:pre-wrap">I have applied for PF final settlement on Apr 26 but till today i didnt get any update .i am requesting you to please speedup the process and settle amount. i have many commitments and medical emergency so please consider and do the needful earliest possible.</span><br><div><br></div><br><div dir="ltr" class="gmail_signature"><div dir="ltr">\n<div>Best,</div>\n<div><br></div>\n<div>Alfred Francis</div>\n<div>AI Architect, Cogniwide</div>\n<div>+91 701 209 7621</div>\n</div></div>\n</div></div>\n<br>\n\n'
text = html2text.html2text(raw_text)
text, signature = extract_signature(text)
@alfredfrancis
alfredfrancis / celery_status_service.py
Last active May 16, 2020 16:00
Flask service to fetch latest celery task status
@app.route('/status/<task_id>')
def taskstatus(project_id,task_id):
task = long_process_task.AsyncResult(task_id)
if task.state == 'PENDING':
# job did not start yet
response = {
'state': task.state,
'current': 0,
'total': 1,
'status': 'Pending...'
@alfredfrancis
alfredfrancis / products.json
Last active April 30, 2020 21:07
Refference JSON for Javascript array functions tutorial
[{
"title": "Brown eggs",
"category": "dairy",
"price": 28.1,
"rating": 4
}, {
"title": "Sweet fresh stawberry",
"category": "fruit",
"price": 29.45,
"rating": 4
"""
1. Setup a Twitter Developer account and create new App, get its consumer key and consumer secret and replace them below
2. Replace TWEETS_DB, QUERY, and LANGUAGE values
3. Install required packages: `pip install tweepy schedule`
4. Run process using `python tweets_to_db.py`
"""
import tweepy
import sqlite3
import datetime
if (window.hasOwnProperty('webkitSpeechRecognition')) {
$(".mic-chat").css({ opacity: 1 })
var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
var recognition = new SpeechRecognition();
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = "en-IN";
recognition.start();
@alfredfrancis
alfredfrancis / base64_encode.py
Created March 27, 2020 18:18
Google Vision API OCR - Python
import base64
with open("yourfile.ext", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
@alfredfrancis
alfredfrancis / docker-compose.traefik.demo.yml
Created March 25, 2020 16:25
Service Discovery and Reverse Proxy for Docker-based Microservices using Traefik
version: '3'
services:
reverse-proxy:
# The official v2 Traefik docker image
image: traefik:v2.1
# Enables the web UI and tells Traefik to listen to docker
command:
- --api.insecure=true
- --api.dashboard=true # <== Enabling the dashboard to view services, middlewares, routers, etc...
@alfredfrancis
alfredfrancis / mongo_wordcloud.py
Created March 5, 2020 14:04
Wordcloud using mongodb data
db.getCollection('cogniwidebot').aggregate([
{
"$project": {
"words": { "$split": ["$query", " "] }
}
},
{
"$unwind": {
"path": "$words"
}
@alfredfrancis
alfredfrancis / progress.component.html
Last active May 16, 2020 15:59
Angular 8 UI for Celery Tasks
<div class="notification-progress" role="alert">
<div class="notification-header">
<span class="close" (click)="removeNotification(notification)">&times;</span>
<h3>{{notification.message}}</h3>
</div>
<div class="notification-body">
<em class="notification-body-content">{{polling_status.status}}</em><br/>
<progress-bar [progress]="polling_status.current" [color-degraded]="{'0': '#ff7777', '35': '#e6ae48', '90': '#00cbcb'}">
</progress-bar>
</div>
inject = document.createElement('script');
inject.src = "https://cogniwide.github.io/cogniassist-chat-widget/public/cogniassist-latest.js";
document.getElementsByTagName('head')[0].appendChild(inject);
var div = document.createElement('div');
document.body.appendChild(div);
div.id = 'cogniassist'