Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / info.md
Created June 12, 2018 16:54 — forked from marteinn/info.md
Using the Fetch Api with Django Rest Framework

Using the Fetch Api with Django Rest Framework

Server

First, make sure you use the SessionAuthentication in Django. Put this in your settings.py

# Django rest framework
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
 'rest_framework.authentication.SessionAuthentication'