Skip to content

Instantly share code, notes, and snippets.

View fpaupier's full-sized avatar
🎲
Focusing

Frαnçois fpaupier

🎲
Focusing
View GitHub Profile
@fpaupier
fpaupier / paragraph_shuffler.py
Last active May 22, 2020 21:21
Shuffle the paragraphs of a text file with python 🐍
#!/usr/bin/python
# -*- coding: utf8 -*-
import codecs
import random
def shuffle_text_paragraphs(file_path, output_file_path):
"""
Args:
@fpaupier
fpaupier / raplyrics.eu.conf
Created September 9, 2018 09:39
Configure a reverse proxy, rewriting rules
<VirtualHost *:80>
 
<some code>
RewriteEngine on
RewriteCond %{SERVER_NAME} =raplyrics.eu [OR]
RewriteCond %{SERVER_NAME} =www.raplyrics.eu
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
@fpaupier
fpaupier / raplyrics.eu-le-ssl.conf
Created September 9, 2018 09:41
Rewrite rules reverse proxy call to API
<IfModule mod_ssl.c>
<VirtualHost *:443>
 <some code>
 ProxyPreserveHost On
 ProxyPass /apiUS http://127.0.0.1:8000/apiUS
 ProxyPassReverse /apiUS https://127.0.0.1:8000/apiUS
<some code>
@fpaupier
fpaupier / pipeline.py
Last active April 12, 2019 11:15
What the steps of an ETL pipeline would look like
"""
Sample extract transform load pipeline to illustrate how Nifi can simplify the construction
of a dataflow.
NOTE: This code is simply to illustrate an idea and is not a working ETL pipeline.
"""
import os
import db_utils
@fpaupier
fpaupier / meeting_scheduler.py
Last active October 20, 2019 01:13
Meeting scheduler - leetcode biweekly contest | https://leetcode.com/problems/meeting-scheduler/
class Solution:
def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]:
n1 = len(slots1)
n2 = len(slots2)
if n1 == 0 or n2 == 0:
return []
idx1 = 0
idx2 = 0
@fpaupier
fpaupier / telegram_update.go
Last active May 25, 2020 04:18
A minimalist Telegram Update struct in Go
// Update is a Telegram object that the handler receives every time an user interacts with the bot.
type Update struct {
UpdateId int `json:"update_id"`
Message Message `json:"message"`
}
@fpaupier
fpaupier / telegram_message.go
Created May 21, 2020 14:15
A minimalist Telegram Message struct in Go
// Message is a Telegram object that can be found in an update.
type Message struct {
Text string `json:"text"`
Chat Chat `json:"chat"`
}
@fpaupier
fpaupier / telegram_char.go
Created May 21, 2020 14:17
A minimalist Telegram Chat struct in Go
// A Telegram Chat indicates the conversation to which the message belongs.
type Chat struct {
Id int `json:"id"`
}
@fpaupier
fpaupier / parseTelegramRequest.go
Last active May 21, 2020 14:52
Parse an incoming Telegram request for webhook update.
// parseTelegramRequest handles incoming update from the Telegram web hook
func parseTelegramRequest(r *http.Request) (*Update, error) {
var update Update
if err := json.NewDecoder(r.Body).Decode(&update); err != nil {
log.Printf("could not decode incoming update %s", err.Error())
return nil, err
}
return &update, nil
}
@fpaupier
fpaupier / rapGeniusBotHandler.go
Created May 21, 2020 14:53
Handler for the Telegram bot @RapGeniusBot
// HandleTelegramWebHook sends a message back to the chat with a punchline starting by the message provided by the user.
func HandleTelegramWebHook(w http.ResponseWriter, r *http.Request) {
// Parse incoming request
var update, err = parseTelegramRequest(r)
if err != nil {
log.Printf("error parsing update, %s", err.Error())
return
}