Skip to content

Instantly share code, notes, and snippets.

View nad2000's full-sized avatar
🇳🇿
Working from New Zealand

Radomirs Cirskis nad2000

🇳🇿
Working from New Zealand
View GitHub Profile
@nad2000
nad2000 / get-git-subdir.sh
Last active August 29, 2015 14:25
How to download a sub-directory from a remote GIT repo
# git archive --remote REPO BRANCH SUBDIR | tar xf -
git archive --remote ssh://[email protected]:7999/ap/appliance.git develop ./tree/customer/endace/tests/injab0x-test | tar tvf -
@nad2000
nad2000 / test.c
Created July 8, 2015 02:52
quit_handler example in C (signal handling)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <inttypes.h>
#include <time.h>
#include <signal.h>
@nad2000
nad2000 / configuration.py
Created May 19, 2015 02:15
Simple configuration implementation form dictionary
class configuration(dict):
def __getattr__(self, name):
return self.get(name)
def __setattr__(self, name, value):
self[name] = value
###
conf = configuration()
@nad2000
nad2000 / flask_threads.py
Created May 13, 2015 04:16
Simple flask app to stress-test multi-threading using curl and xargs
# RUN FORM BASH:
# echo http://127.0.0.1:5000/?{1..1000} | xargs -n 1 -P 1000 curl -s
from flask import Flask, Response
import time
request_count = 0
app = Flask(__name__)
@app.route("/")
@nad2000
nad2000 / curl_example.sh
Last active August 29, 2015 14:12
example how to use curl
CURL="curl -k -b cookies.txt -c cookies.txt"
$CURL --data "d_user_id=user_id&t_user_id=string&c_user_id=string&e_user_id=true&f_user_id=admin&f_password=injab0xn&Login=Login" "http://${TARGET_HOST}/admin/launch?script=rh&template=login&action=login"
$CURL "http://${TARGET_HOST}/vision/visualizations"
@nad2000
nad2000 / test.c
Created December 17, 2014 04:41
Basic examples to show how to embed and extend Python in C including: creation of module in C with functions handling and building Python objects; importing and calling python functions from C.
/* Example of embedding Python in another program */
// to compile run:
// gcc -o test $(python-config --cflags) test.c $(python-config --ldflags) && ./test
#include<stdio.h>
#include "Python.h"
void initxyzzy(void); /* Forward */
main(int argc, char **argv)
@nad2000
nad2000 / current_script_directory.sh
Created December 16, 2014 01:43
BASH script execution directory for either run in spawned process or sourced source
# $SD - script installation directory (e.g. /opt/tms/lib/dbmgr
# for packages it can be arbitrary location)
[ -z "$SD" -o ! -e "$SD" ] && SD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
while true ; do echo -n $RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM | tr "0" "*" ; sleep "0.$RANDOM" ; echo $RANDOM$RANDOM$RANDOM ; sleep "0.$RANDOM" ;done
@nad2000
nad2000 / pattern.sh
Created June 24, 2014 01:46
Pattern matching for $1 = '6028276268421821235', $2 = '6028276268851317965', $3 = '85899200', $4 = NULL, $5 = NULL, $6 = NULL, $7 = 'byte', $8 = '10' and $1 = '6028276268421821235', $2 = '6028276268851317965', $3 = '85899200', $4 = NULL, $5 = NULL, $6 = NULL, $7 = 'byte', $8 = '10'
grep -E "\\\$1 = '[0-9]+', \\\$2 = '[0-9]+', \\\$3 = '[0-9]+', \\\$4 = '[0-9]+'" /endace/pgsql/pg_log/postgresql-24.log | sed -n "s/.*'\([0-9]*\)'.*'\([0-9]*\)'.*'\([0-9]*\)'.*'\([0-9]*\)'.*/\1,\2,\3,\4/p"
grep -E "\\\$1 = '[0-9]+', \\\$2 = '[0-9]+', \\\$3 = '[0-9]+', \\\$4 = NULL, \\\$5 = NULL, \\\$6 = NULL, \\\$7 = 'byte'" /endace/pgsql/pg_log/postgresql-24.log | sed -n "s/.*'\([0-9]*\)'.*'\([0-9]*\)'.*'\([0-9]*\)'.*'\([0-9]*\)'.*/\1,\2,\3,\4/p"
grep -E "\\\$1 = '[0-9]+', \\\$2 = '[0-9]+', \\\$3 = '[0-9]+', \\\$4 = NULL, \\\$5 = NULL, \\\$6 = NULL, \\\$7 = 'byte'" /endace/pgsql/pg_log/postgresql-24.log | sed -n "s/.*'\([0-9]*\)'.*'\([0-9]*\)'.*'\([0-9]*\)'.*'\([0-9]*\)'.*/\1,\2,\3,\4/p" | awk -F, '{print $1,$2,$3,$4, $2-$1}'
@nad2000
nad2000 / fast_file_copy.sh
Created March 21, 2014 03:22
Fast file copy using NC #nc #netcat #transfer #copy
# on the source (appbuild-vm4):
nc -l 7879 < /data/Traces/telstra_nexus.erf
# on the target
nc appbuild-vm4 7879 > /data/telstra_nexus.erf
## I have tried with compression, but with fast network it performed poorer (in my case with 11GB file 15 min vs. 1.5 min):