Skip to content

Instantly share code, notes, and snippets.

View davidrios's full-sized avatar

David Rios davidrios

  • São Paulo, Brazil
View GitHub Profile
# -*- coding: utf-8 -*-
import gettext
import re
import threading
from datetime import datetime, time
import pytz
from babel import dates, numbers
class PersistentDict(object):
def __init__(self, store_file):
self._store_file = store_file
self._is_modified = False
self.reload()
def reload(self):
if self._is_modified:
raise Exception('data was modified and not persisted')
import asyncio
import signal
from random import random
_stop_all = []
simulate_erros = []
@asyncio.coroutine
def consumer(queue):
@davidrios
davidrios / modsecurity2_ubuntu.md
Created November 6, 2015 14:10
install modsecurity 2.9 from source on ubuntu

modsecurity 2.9 with owasp core rule set

install on ubuntu 12.04/14.04 for apache2

as root

apt-get update
apt-get dist-upgrade  # not mandatory but recommended
apt-get install apache2-dev libxml2-dev liblua5.1-0-dev libcurl4-gnutls-dev libyajl-dev make curl

10-minute guide to start Python web development on Windows

  1. Navigate on your web browser to https://www.python.org/downloads
  2. Click on Download Python 2.7.11
  3. Install the downloaded package using the default settings
  4. Open a terminal prompt: WindowsKey + R -> cmd.exe -> Enter
  5. Type: c:\python27\scripts\pip.exe install bottle
  6. Open windows explorer, navigate to your Documents folder, create a new folder called webdev1 and navigate to it
  7. Press Alt key on keyboard, click on File -> New -> Text Document
  8. Name your new file test1.py and open it with a text editor, standard notepad will do, but you will not be able to edit it by double-clicking on the file
#!/usr/bin/env python3
import json
import sqlite3
from http.server import HTTPServer, BaseHTTPRequestHandler
conn = sqlite3.connect('requests.db')
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS requests (id integer primary key, datetime text, method text, headers text, body blob)''')
#!/bin/bash
RESP=$(cat <<EOF | fzf
Logout
Sleep
Reboot
Shutdown
EOF
);
#!/bin/env python3
import logging
import json
import sys
from configparser import RawConfigParser, NoOptionError
from itertools import chain
from locale import getlocale
from pathlib import Path
log = logging.getLogger(__name__)
#!/bin/bash
NAME=$(/usr/local/bin/find-desktop-apps | fzf -d: --with-nth 2 | cut -d: -f1)
[ -z "$NAME" ] && exit
swaymsg exec "gtk-launch $NAME"
#!/bin/bash
set -e
if [ $(id -u) -eq 0 ]; then
echo 'Please execute this script as a regular user.'
exit 1
fi
which sudo >/dev/null
if [ $? -ne 0 ]; then