Skip to content

Instantly share code, notes, and snippets.

@shouro
shouro / drf-nested-views.py
Created Jan 28, 2020 — forked from dkarchmer/drf-nested-views.py
Example of a Django Rest Framework ViewSet with nested views
View drf-nested-views.py
# ViewSets define the view behavior.
class FooViewSet(viewsets.ModelViewSet):
lookup_field = 'slug'
queryset = Foo.objects.all()
serializer_class = FooSerializer
def get_queryset(self):
"""
This view should return a list of all records
"""
@shouro
shouro / ssh.md
Created Sep 29, 2019 — forked from bradtraversy/ssh.md
SSH & DevOps Crash Course Snippets
View ssh.md

SSH Cheat Sheet

This sheet goes along with this SSH YouTube tutorial

Login via SSH with password (LOCAL SERVER)

$ ssh brad@192.168.1.29

Create folder, file, install Apache (Just messing around)

$ mkdir test

$ cd test

@shouro
shouro / ec2.tf
Created May 4, 2018 — forked from solarce/ec2.tf
terraform.io example template for ec2 instance with tags
View ec2.tf
# The various ${var.foo} come from variables.tf
# Specify the provider and access details
provider "aws" {
region = "${var.aws_region}"
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
}
@shouro
shouro / INIT_VAULT.md
Created May 4, 2018 — forked from moertel/INIT_VAULT.md
Try Vault with MySQL storage backend (via Docker)
View INIT_VAULT.md

Initialise (will return keys and a token)

curl -X PUT http://0.0.0.0:8200/v1/sys/init --data '{"secret_shares":1, "secret_threshold":1}'

Use one of the keys to unseal

curl -X PUT http://0.0.0.0:8200/v1/sys/unseal --data '{"key":"a5e665962f544dd16471c120c5500a7906cfbaeb3f18ae0fc6c5c71d444f0a90"}'

Use the root token to store something

@shouro
shouro / nginx.conf
Created Apr 26, 2017 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
View nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
View bash.generate.random.alphanumeric.string.sh
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@shouro
shouro / daemon.md
Created Jan 26, 2016 — forked from andreif/daemon.md
A simple unix/linux daemon in Python
View daemon.md

A simple unix/linux daemon in Python

Source: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

Access: http://web.archive.org/web/20131025230048/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

by Sander Marechal

I've written a simple Python class for creating daemons on unix/linux systems. It was pieced together for various other examples, mostly corrections to various Python Cookbook articles and a couple of examples posted to the Python mailing lists. It has support for a pidfile to keep track of the process. I hope it's useful to someone.

@shouro
shouro / gist:c8d14c42f085a9a11928
Created Jan 19, 2016
Python AES two-way encryption/decryption example
View gist:c8d14c42f085a9a11928
from Crypto.Cipher import AES
import base64
import os
# the block size for the cipher object; must be 16, 24, or 32 for AES
BLOCK_SIZE = 32
# the character used for padding--with a block cipher such as AES, the value
# you encrypt must be a multiple of BLOCK_SIZE in length. This character is
# used to ensure that your value is always a multiple of BLOCK_SIZE
View app.py
import os
from autobahn.resource import WebSocketResource, WSGIRootResource
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
from flask import Flask, render_template
from twisted.application import internet, service
from twisted.internet import reactor
from twisted.python.threadpool import ThreadPool
from twisted.web.server import Site
@shouro
shouro / README.md
Last active May 24, 2019
This python script will list your public and private gist.
View README.md

List git gist

This script will print the output in HTML format on stdout.

Console command

$ python list_your_gitgist.py > out.html

You can’t perform that action at this time.