Skip to content

Instantly share code, notes, and snippets.

@silviud
silviud / ssh.sh
Created December 17, 2017 13:48
SSH Cheatsheet
Base Usage
ssh [user]@[host]
Use Specific Key
ssh -i ~/.ssh/id_rsa [user]@[host]
Use Alternative Port
ssh -i ~/.ssh/id_rsa -p [port] [user]@[host]
@silviud
silviud / services.py
Created September 25, 2017 08:52 — forked from mixxorz/services.py
Django Service Objects
from django import forms
from django.core.exceptions import ValidationError
from django.db import transaction
class InvalidInputsError(Exception):
def __init__(self, errors, non_field_errors):
self.errors = errors
self.non_field_errors = non_field_errors
@silviud
silviud / php-fpm
Created September 19, 2017 12:51 — forked from fprochazka/php-fpm
php-fpm config files & init.d script
#!/bin/bash
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm daemon
# Description: starts php-fpm daemon
@silviud
silviud / logstash.index.json
Last active September 18, 2017 17:51 — forked from WPsites/logstash.index.json
Elasticsearch index template for logstash that contains additional NGINX fields
// fluentd conf
<source>
@type tail
path /var/log/nginx/access.log #...or where you placed your Apache access log
pos_file /var/log/td-agent/nginx-access.log.pos # This is where you record file position
tag nginx.access #fluentd tag!
format /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" "(?<end>)[^\"]*")?$/
time_format %d/%b/%Y:%H:%M:%S %z
</source>
@silviud
silviud / beautiful_idiomatic_python.md
Created July 4, 2017 12:46 — 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]:
@silviud
silviud / recover_source_code.md
Created March 11, 2017 14:04 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@silviud
silviud / gist:3f41aba4f8f58a7f6af4208e4462057e
Created January 20, 2017 19:40
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@silviud
silviud / API.md
Created January 19, 2017 16:28 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@silviud
silviud / gist:c48be89b57e819562a43eb463f1c6016
Created December 13, 2016 23:17
Self sign OpenSSL certficate
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
@silviud
silviud / gist:943d4cba3dba29ea826cf5e68f619c20
Last active December 12, 2016 23:39
Zabbix API register/deregister
# boto instance tags
import boto.ec2
conn = boto.ec2.connect_to_region('us-west-2')
# Find a specific instance, returns a list of Reservation objects
# http://boto.cloudhackers.com/en/latest/ref/ec2.html#boto.ec2.connection.EC2Connection.get_all_reservations
reservations = conn.get_all_instances(instance_ids=['i-xxxxxxxx'])
# Find the Instance object inside the reservation
instance = reservations[0].instances[0]
internal_dns = instance.private_dns_name