This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Instead of doing a + b + c, use ''.join([a, b, c]) syntax for concatenating multiple strings. | |
| Similarly, you want to join multiple paths, you will use dirname + 'xxx.jpg' to form a path. | |
| Instead, use this python syntax - os.path.join(os.path.sep, dirname, 'xxx.jpg') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| logstash with strace | |
| ---------------------- | |
| strace -o /tmp/strace.log -fe trace=network /opt/logstash/bin/logstash -f your.conf | |
| check logstash configuration | |
| ------------------------------ | |
| /opt/logstash/bin/logstash -f your.conf --configtest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| All the limits are declared in in /etc/limits.conf - or in /etc/limits.d and these are displayed by 'ulimit -n'. | |
| 'nofile' - the number of open files | |
| You can make use of 'lsof' for monitoring open files per processes. | |
| root@psj-desktop:~# lsof | awk '$4 ~ /[0-9]+[rwu -].*/{p[$1"\t"$2"\t"$3]=p[$1"\t"$2"\t"$3]+1}END{for (i in p) print p[i],i}' | sort -n | tail | |
| Otherwise, you can make use of /proc file system on linux: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # | |
| # K-means clustering using Lloyd's algorithm in pure Python. | |
| # Written by Lars Buitinck. This code is in the public domain. | |
| # | |
| # The main program runs the clustering algorithm on a bunch of text documents | |
| # specified as command-line arguments. These documents are first converted to | |
| # sparse vectors, represented as lists of (index, value) pairs. | |
| from collections import defaultdict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| input { | |
| tcp { | |
| type => "syslog" | |
| host => "127.0.0.1" | |
| port => 3514 | |
| } | |
| tcp { | |
| type => "eventlog" | |
| host => "10.1.1.2" | |
| port => 3515 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function and attributes of python module | |
| >>> import django | |
| >>> dir(django) | |
| ['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'get_version'] | |
| # find path for a module | |
| >>> print django.__file__ | |
| '/usr/local/lib/python2.6/dist-packages/django/__init__.pyc' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Install Python 3.4 on CentOS | |
| $ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz | |
| $ tar -xvf Python-3.4.3.tar.xz | |
| $ cd Python-3.4.3 | |
| $ su | |
| # yum groupinstall "Development tools" | |
| # exit | |
| $ sudo ./configure | |
| $ sudo make | |
| $ sudo make install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Reference link - http://www.cyberciti.biz/tips/linux-iptables-examples.html | |
| # Clear any previous rules. | |
| /sbin/iptables -F | |
| # Default drop policy. | |
| /sbin/iptables -P INPUT DROP | |
| /sbin/iptables -P OUTPUT ACCEPT | |
| # Allow anything over loopback and vpn. | |
| /sbin/iptables -A INPUT -i lo -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT | |
| /sbin/iptables -A OUTPUT -o lo -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # use of subprocess | |
| import subprocess | |
| # check whether kernel.exec-shield=1 is True or not using - sysctl -a |grep 'kernel.exec-shield=1' | |
| #result = subprocess.Popen('sysctl -a | grep "kernel.exec-shield=1"', shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) | |
| result = subprocess.Popen('sysctl -a | grep "kernel.exec-shield=1"', shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) | |
| stdout,stderr=result.communicate() | |
| # the result will be a byte buffer. convert bytes to string: | |
| print stdout.decode('utf-8') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>>from netaddr import IPNetwork, IPAddress | |
| >>>if IPAddress("192.168.0.1") in IPNetwork("192.168.0.0/24"): | |
| print "Yes!" | |
| >>>import ipaddress | |
| >>> ipaddress.ip_address('192.168.0.1') in ipaddress.ip_network('192.168.0.0/24') | |
| True |