Skip to content

Instantly share code, notes, and snippets.

View ninjadq's full-sized avatar
Σ(°Д°;

DQ ninjadq

Σ(°Д°;
View GitHub Profile
@ninjadq
ninjadq / restart_celery.sh
Last active February 10, 2017 08:31
script for django celery and gunicorn
#!/bin/bash
echo 'kill celery workers....\n'
kill `cat celeryd.pid`
sleep 2.5
echo 'kill celerybeat....'
kill `cat celerybeat.pid`
sleep 1
echo 'start celery worker...'
celery -A monitorsystem worker -l error --detach --logfile="celeryworker.log"
@ninjadq
ninjadq / bash.py
Created March 16, 2016 02:16 — forked from kirpit/bash.py
Enables to run subprocess commands in a different thread with TIMEOUT option!
#! /usr/bin/env python
import threading
import subprocess
import traceback
import shlex
class Command(object):
"""
Enables to run subprocess commands in a different thread with TIMEOUT option.
@ninjadq
ninjadq / reflect.py
Created March 16, 2016 02:13 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@ninjadq
ninjadq / sample.py
Created March 3, 2016 05:21
django transactions with raw sql and multiple databases
def test_transaction(*args):
create_sql = "INSERT INTO user (name) VALUES (%s)"
transaction.set_autocommit(False, using='uic')
try:
cursor = connections['uic'].cursor()
for u in args:
cursor.execute(create_sql,[u])
except IntegrityError as e:
transaction.rollback(using='uic')
else:
@ninjadq
ninjadq / db.sql
Created January 15, 2016 05:04
sql_alchemy example
-- tables
-- Table: client
CREATE TABLE client (
id int NOT NULL,
full_name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
CONSTRAINT client_pk PRIMARY KEY (id)
);
-- Table: purchase
@ninjadq
ninjadq / profile.py
Created November 7, 2015 07:50
flask profile
#!flask/bin/python
from werkzeug.contrib.profiler import ProfilerMiddleware
from app import app
app.config['PROFILE'] = True
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) ## to show the 30 most expensive functions for each request
app.run(debug = True)
@ninjadq
ninjadq / gist:4d4c38b0828669e789bb
Created October 12, 2015 02:27
add macvlan to a container
#!/bin/bash
ip link add em1p0 link em2 type macvlan mode bridge
ip link set netns $@ em1p0
nsenter -t $@ -n ip link set em1p0 up
nsenter -t $@ -n ip route del default
nsenter -t $@ -n ip addr add 118.26.188.97/24 dev em1p0
nsenter -t $@ -n ip route add default via 118.26.188.254 dev em1p0
@ninjadq
ninjadq / docker-ovs.md
Created October 10, 2015 03:03 — forked from noteed/docker-ovs.md
Docker - Open vSwitch setup