Related Posts
javascript: Get N random elements from a List
[javascript] /** * Walks linearly through the list to find an element. * returns true if it’s found. */ function elementIn(collection, element) { for (var i=0; i < collection.length; i++) { if (collection[i]==element) { return true; } } return false; } /** * Returns a new list of n random elements taken out of myList. […]
How to ban/unban ips in linux
In case you’re not an iptables guru, you might want to create a couple scripts and put em somewhere on your $PATH. I’ve created two scripts called ban_ip and unban_ip. Create a file called ban_ip touch ban_ip chmod +x ban_ip Edit it and copy the following code inside: #!/bin/bash sudo iptables -A INPUT -s $1 […]
[CODE/PHP] JpGraph: How to output your graph as a base64 encoded image
Some times you just want to output the image created by your $graph object without having to create a separate .php script that would need to receive a bunch of parameters. Here’s a function you can pass your $graph object right before the $graph->Stroke(); call [pastacode lang=”php” manual=”function%20graphInSrc(%24graph%2C%20%24width%2C%20%24height)%20%7B%0A%20%20%24img%20%3D%20%24graph-%3EStroke(_IMG_HANDLER)%3B%0A%20%20ob_start()%3B%0A%20%20imagepng(%24img)%3B%0A%20%20%24img_data%20%3D%20ob_get_contents()%3B%0A%20%20ob_end_clean()%3B%0A%0A%20%20echo%20’%3Cimg%20width%3D%22′.%24width.’%22%20height%3D%22′.%24height.’%22%20src%3D%22data%3Aimage%2Fpng%3Bbase64%2C’.base64_encode(%24img_data).’%22%2F%3E’%3B%0A%7D” message=”” highlight=”” provider=”manual”/]