Skip to content

Instantly share code, notes, and snippets.

@ctrngk
ctrngk / 0readme.md
Created May 23, 2018 02:46 — forked from mdamien/0readme.md
404 link detector with scrapy

List all the broken links on your website

Requirements:

python3 and scrapy (pip install scrapy)

Usage

  • scrapy runspider -o items.csv -a site="https://yoursite.org" 1spider.py
  • python3 2format_results.py
@ctrngk
ctrngk / TorPrivoxyPython.md
Created May 19, 2018 09:29 — forked from DusanMadar/TorPrivoxyPython.md
A step-by-step guide how to use Python with Tor and Privoxy
@ctrngk
ctrngk / withsqlite.py
Created April 30, 2018 05:11 — forked from miku/withsqlite.py
Simple sqlite3 context manager for Python.
#!/usr/bin/env python
import sqlite3
class dbopen(object):
"""
Simple CM for sqlite3 databases. Commits everything at exit.
"""
def __init__(self, path):
self.path = path
@ctrngk
ctrngk / web-servers.md
Created April 4, 2017 06:18 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@ctrngk
ctrngk / uninstall.sh
Created March 31, 2017 08:55 — forked from myusuf3/uninstall.sh
how to cleanly uninstall python packages installed with python setup.py
# Next time you need to install something with python setup.py -- which should be never but things happen.
python setup.py install --record files.txt
# This will cause all the installed files to be printed to that directory.
# Then when you want to uninstall it simply run; be careful with the 'sudo'
cat files.txt | xargs sudo rm -rf
@ctrngk
ctrngk / gist:b562ac8bea6b90c0aafb06b266b8805a
Created March 12, 2017 00:06 — forked from issackelly/gist:928783
Django Template {{ block.super }} example
# Template: A.html
<html>
<head></head>
<body>
{% block hello %}
HELLO
{% endblock %}
</body>
</html>
@ctrngk
ctrngk / Doc.rst
Created March 11, 2017 23:51 — forked from copitux/Doc.rst
Django, Django forms and Django rest framework: Payload validation

Django request flow

-------------------------------                         ------------------ Django --------------------
| Browser: GET /udo/contact/2 |    === wsgi/fcgi ===>   | 1. Asks OS for DJANGO_SETTINGS_MODULE      |
-------------------------------                         | 2. Build Request (from wsgi/fcgi callback) |
                                                        | 3. Get settings.ROOT_URLCONF module        |
                                                        | 4. Resolve URL/view from request.path      | # url(r'^udo/contact/(?P<id>\w+)', view, name='url-identifier')
                                                        | 5. Apply request middlewares               | # settings.MIDDLEWARE_CLASSES
@ctrngk
ctrngk / skeleton-daemon.sh
Created March 4, 2017 13:09 — forked from shawnrice/skeleton-daemon.sh
A template to write a quick daemon as a bash script
#!/bin/sh
# This is a skeleton of a bash daemon. To use for yourself, just set the
# daemonName variable and then enter in the commands to run in the doCommands
# function. Modify the variables just below to fit your preference.
daemonName="DAEMON-NAME"
pidDir="."
pidFile="$pidDir/$daemonName.pid"
@ctrngk
ctrngk / namedPipes.sh
Created February 28, 2017 04:49 — forked from torgeir/namedPipes.sh
how to message daemon process - bash pipe as stdin
# create pipe, tail it, and read from stdin in a program
mkfifo namedPipe; tail -f namedPipe | while true; do read msg; echo $msg; done;
# now send messages from another shell
echo "start" > namedPipe
echo "stop" > namedPipe
@ctrngk
ctrngk / daemon.md
Created February 24, 2017 14:52 — forked from andreif/daemon.md
A simple unix/linux daemon in Python

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.