Skip to content

Instantly share code, notes, and snippets.

View cnicodeme's full-sized avatar

Cyril Nicodème cnicodeme

View GitHub Profile
@cnicodeme
cnicodeme / migrate.py
Created August 30, 2018 12:07
Migration script to do raw SQL requests
# Add this import:
from sqlalchemy.sql import text
def upgrade():
# ...
conn = op.get_bind()
conn.execute(text('UPDATE ...'))
# ...
@cnicodeme
cnicodeme / pdfshift.php
Last active December 6, 2021 13:30
PDFShift PHP curl_ request
<?php
/**
* Example of usage:
* ```
* pdfshift('your_api_key', array(
* 'source' => 'http://www.example.com',
* 'use_print' => true
* ));
*/
function pdfshift($apiKey, $params) {
@cnicodeme
cnicodeme / deploy.sh
Last active May 3, 2018 15:11
Deploy a new NGinx serrver with git, Auto deploy, Supervisor+uWSGI
#!/bin/bash
read -e -p "Project Name: " project_name
mkdir -p "/var/www/$project_name/project.git"
cd "/var/www/$project_name/project.git"
git init --bare
cd "/var/www/$project_name/"
@cnicodeme
cnicodeme / spamd.py
Last active December 8, 2017 11:01
Postfix SPAM checker with deletion
# -*- config:utf-8 -*-
import socket, select, re, logging
from io import BytesIO
divider_pattern = re.compile(br'^(.*?)\r?\n(.*?)\r?\n\r?\n', re.DOTALL)
first_line_pattern = re.compile(br'^SPAMD/[^ ]+ 0 EX_OK$')
@cnicodeme
cnicodeme / server.sh
Last active April 11, 2022 14:38
server-nginx-flask.sh
#!/bin/bash
# First of all, we check if the user is root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Changing the password of the root user
read -e -p "Do you want to change the root password? [Y/n] : " change_password
@cnicodeme
cnicodeme / server.sh
Created June 28, 2017 15:30
Installation script - automated - for an Nginx server with MySQL on Debian
#!/bin/bash
#
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 3.0 or above
# Copyright (C) 2005 ReFlectiv project.
# Feedback/comment/suggestions : http://www.reflectiv.net/
# -------------------------------------------------------------------------
#
# This script automatically set up a new *Debian* server (IMPORTANT : Debian!), by doing these actions :
#
@cnicodeme
cnicodeme / google_dataflow_xlsx.py
Created December 9, 2016 13:42
My first attempt at processing an Xlsx file on Google DataFlow service.
import logging, argparse
import apache_beam as beam
from apache_beam.io import gcsio
from apache_beam.utils.options import PipelineOptions
from openpyxl import load_workbook
# @See https://cloud.google.com/dataflow/model/custom-io-python#ptransform-wrappers
@cnicodeme
cnicodeme / install.sh
Created November 15, 2016 13:55
Installation script for Fedora 24
#!/bin/bash
dnf -y remove cheese evolution libreoffice* shotwell empathy
# Installing repositories
dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
dnf -y install http://rpms.famillecollet.com/fedora/remi-release-24.rpm
# Installing Google Chrome repository
@cnicodeme
cnicodeme / wordpress.export.php
Created October 20, 2016 09:33
Wordpress XML export creation in PHP
<?php
date_default_timezone_set('UTC');
define('DATE_FORMAT', '%a, %d %b %Y %H:%M:%S +0000');
$domain = 'blog.cnicodeme.com';
$blogId = 1;
$pdo = new PDO('mysql:dbname=postera;host=127.0.0.1', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@cnicodeme
cnicodeme / 0reflectiv.net-wordpress.xml
Last active October 20, 2016 09:43
Our previous Wordpress blog, in case of nostalgia :)
<?xml version="1.0"?>
<rss xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.2/" version="2.0"><channel><title>Cyril's blog</title><link>http://blog.cnicodeme.com</link><description>Adventures of an entrepreneur</description><pubDate>Thu, 20 Oct 2016 09:02:39 +0000</pubDate><language>en-US</language><wp:wxr_version xmlns:wp="wp">1.2</wp:wxr_version><wp:base_site_url xmlns:wp="wp">http://cnicodeme.com</wp:base_site_url><wp:base_blog_url xmlns:wp="wp">http://blog.cnicodeme.com</wp:base_blog_url><generator>https://wordpress.org/?v=4.6.1</generator><item><title>Taille de certaines balises HTML pour les moteurs de recherche</title><link>http://blog.reflectiv.net/taille-de-certaines-balises-html-pour-les-mot</link><pubDate>Mon, 17 May 2010 17:37:00 +0000</pubDate><dc:creator><![CDATA[Cyril Nicodème]]></dc:creator><guid is