Skip to content

Instantly share code, notes, and snippets.

View rodfersou's full-sized avatar

Rodrigo Ferreira de Souza rodfersou

  • Londrina - PR, Brazil
View GitHub Profile
@rodfersou
rodfersou / .gitignore
Created December 9, 2023 01:40 — forked from datakurre/.gitignore
Multi-kernel Jupyter notebook environment and Docker container with Nix
*.ipynb
*.png
*.tar.gz
.ipynb_checkpoints
.ipython
.jupyter
.sentinel.*
@rodfersou
rodfersou / README
Created August 19, 2023 05:27 — forked from jmatsushita/README
Setup nix, nix-darwin and home-manager from scratch on an M1 Macbook Pro
###
### [2023-06-19] UPDATE: Just tried to use my instructions again on a fresh install and it failed in a number of places.
###. Not sure if I'll update this gist (though I realise it seems to still have some traffic), but here's a list of
###. things to watch out for:
### - Check out the `nix-darwin` instructions, as they have changed.
### - There's a home manager gotcha https://github.com/nix-community/home-manager/issues/4026
###
# I found some good resources but they seem to do a bit too much (maybe from a time when there were more bugs).
# So here's a minimal Gist which worked for me as an install on a new M1 Pro.
# -*- coding: utf-8 -*-
""" bin/instance -O Plone run reorder_menu.py """
from collections import OrderedDict
from plone import api
from plone.dexterity.interfaces import IDexterityContent
import transaction
# get total requests by status code
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
# get top requesters by IP
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requesters by user agent
cut -d' ' -f12- /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# get top requests by URL
@rodfersou
rodfersou / import.py
Last active March 16, 2017 12:40
Import ssh configs from digital ocean
# -*- coding: utf-8 -*-
from glob import glob
from itertools import izip
from lxml import html
# elements by CSS class; http://stackoverflow.com/a/1604480
CLASS_SELECTOR = '//*[contains(concat(" ", normalize-space(@class), " "), " {0} ")]'
TEMPLATE = '''
Host {title}_
@rodfersou
rodfersou / aliases.sh
Last active August 11, 2016 13:34
Alias to easily move into Plone project
# go to git root directory
alias cdr='gitroot=`git rev-parse --show-toplevel`; cd $gitroot'
# go to git project directory
alias cdp='cdr; giturl=`git config --get remote.origin.url`; folder=${${${giturl##*/}%.*}//.//}; if [ -d "$folder" ]; then cd "$folder"; elif [ -d "src/$folder" ]; then cd "src/$folder"; fi'
# go to omelette directory
alias cdo='cdr; om1=parts/packages; om2=parts/omelette; if [ -d "$om1" ]; then cd "$om1"; elif [ -d "$om2" ]; then cd "$om2"; fi'
# References:
# https://help.ubuntu.com/community/btrfs#Snapshots_.26_Subvolumes
# http://superuser.com/questions/795903/how-to-snapshot-a-btrfs-root-file-system-snapshot-of
# http://serverfault.com/questions/399894/does-btrfs-have-an-efficient-way-to-compare-snapshots
teste@teste-VirtualBox:~$ vi btrfs-diff
teste@teste-VirtualBox:~$ vi script.sh
teste@teste-VirtualBox:~$ chmod +x btrfs-diff script.sh
teste@teste-VirtualBox:~$ sudo btrfs subvolume snapshot / /snap/root -r
@rodfersou
rodfersou / beautiful_idiomatic_python.md
Last active March 4, 2016 20:43 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
# XXX -- Top level review comments:
#
# * Nice exception recovery and logging.
#
# * Please cleanup code formatting.
# This is a little rough on my eyes.
#
# * Should we use this as template for other
# short network element scripts?
#
from nettools import NetworkElement
with NetworkElement('171.0.2.45') as ne:
for route in ne.routing_table:
print '%15s -> %s' % (route.name, route.ipaddr)