Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Atala's full-sized avatar

Aloïs Guillopé Atala

View GitHub Profile
@Atala
Atala / add_filter_example.php
Last active June 4, 2016 15:38
Add filter example
<?php
add_filter('post_thumbnail_html', 'get_first_image_if_no_thumb');
function get_first_image_if_no_thumb($html, $post_id, $post_image_id) {
if ($html == '') {
$post = get_post($post_id);
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches[1][0];
if (isset($first_img)) {
return '<img width="300" class="attachment-medium size-medium wp-post-image" src='. $first_img .'></img>'
{
"2016-04-11 00:00:00": [
"Un pouvoir bi parti avec bin\u00f4me \u00e9conomiste et technicien de terrain",
"Convergence \u2013 Mise en lumi\u00e8re de nos propres m\u00e9dias \u2013 Radios (ex\u00a0: 89 \u2013 4)\u00a0: \n\nArtistes (musiciens \u00ab\u00a0engag\u00e9s\u00a0\u00bb), les piliers de l\u2019art.\nCroiser les th\u00e8mes de lutte et \u00ab\u00a0les th\u00e8mes de vie\u00a0: manger, aimer, dormir.\nSimplifier notre COM.. R\u00e9flexion autour abr\u00e9viations, jargons et pr\u00e9jug\u00e9s",
"En plus de la gr\u00e8ve g\u00e9n\u00e9rale, COUPER LES FINANCES DE L\u2019ETAT Comment\u00a0? EN TRANSFERANT L\u2019EPARGNE DES LIVRETS REGLEMENT\u00c9 (Livret A, LDD etc..) Sur compte \u00e0 vue ou compte courant\n\t350 MILLIARDS D\u2019EPARGNE DONT SE SERT L\u2019ETAT POUR SE FINANCER et d\u00e9tenu sur ses livrets. SI TOUT LE MONDE TRANSFERE CETTE EPARGNE ONT LES METS A GENOUX.\n\tCHAQUE Jour un virement.",
"Je suis favorable \u00e0 l\u2019abolition de la Ve R\u00e9publique et l\u2019
#!/bin/env/python3
import re
import requests
from bs4 import BeautifulSoup as BS
db = {}
if __name__ == '__main__':
@Atala
Atala / redis_key_sizes.sh
Created May 4, 2016 10:39 — forked from epicserve/redis_key_sizes.sh
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
import os
class RemoveFileContextManager(object):
def __init__(self, filename):
self.filename = filename
def __enter__(self):
pass
@Atala
Atala / nginx
Last active December 17, 2015 14:36
OpenResty init.d script for Amazon AMI
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/openresty/nginx/conf/nginx.conf
# pidfile: /var/run/nginx.pid
# -*-coding:utf-8-*-
#!/usr/bin/env python
import flowdock
import argparse
FLOWDOCK_API_KEY = "XXXX"
FLOWDOCK_USERNAME = "Monit"
FLOWDOCK_TAGS = ["#alert"]
chat = flowdock.Chat(FLOWDOCK_API_KEY)
@Atala
Atala / mem_to_cloudwatch.py
Created August 10, 2015 10:20
Thanks to Shahar Evron for this script.
#!/usr/bin/env python
'''
Send memory usage metrics to Amazon CloudWatch
This is intended to run on an Amazon EC2 instance and requires an IAM
role allowing to write CloudWatch metrics. Alternatively, you can create
a boto credentials file and rely on it instead.
Original idea based on https://github.com/colinbjohnson/aws-missing-tools
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
ssl_dhparam /etc/nginx/cert/dhparams.pem;
@Atala
Atala / messagepack_streaming.md
Created January 19, 2015 14:56
Note on messagepack unpacking

As I understand, this won't work:

import msgpack
fd = sock.makefile("rb")
unpacker = msgpack.Unpacker(fd, encoding="utf-8")
packet = unpacker.next()

From the msgepack python implementation, the unpacker will emit this: