Friday, December 4, 2015

Javascript tips and tricks

You can access a HTML element id by

Type the id name directly in broswer console eg, my div id = makeCall
makeCall
Suppose if id with '_' , like make_Call it won't work

Use getElement, Works in all case
document.getElementById('makeCall')

or Query selector, it doesn't like id with numbers at start :P
document.querySelector('#makeCall')










If you want to use script or a function in HTML form action you can use 'javascript:myFunction();'



action="javascript:myFunction();

Javascript access functions and variables inside Jquery

(function($) {
$.fn.mainFunction = new function (){
var testVal = "Test";
this.test = function(){
console.log('inside test');
}
}
}(jQuery));

Now you can access testVal and mainFunction.test()

Tuesday, December 1, 2015

Moniter/Listen/Load test http request Linux

There is a simple tool tcpflow to capture the actual headers coming to your host

tcpflow port 80

To be more specific use.
tcpflow -p -c -i eth0 port 80 | grep -oE '(GET|POST|HEAD) .* HTTP/1.[01]|Host: .*'

Capture only number of hits: 
tcpflow -p -c -i eth0 port 80 | grep 'Date'


Use ab tool (apache2-tools) to benchmark the load on apache or any other http server like pyhton,node etc

ab -n 1000 -c 10 http:ipaddresss:port/                    / is important after port number 

-n number of request to send
-c total request to send per sec / concurrent req


You can use rate limit to allow number of connection per sec/min/hr with --limit module in IPTABLES

Iptables -A INPUT -p tcp --dport 80 -m state --state NEW -m limit --limit 10/second --limit-burst 10 -j ACCEPT

CSS tricks

Mixed paint in background: background: linear-gradient(to right, #b6e358, #38b143) Grid view: display: grid; grid-template-columns: a...