Skip to content

Instantly share code, notes, and snippets.

View avin's full-sized avatar
🚀

Avin Lambrero avin

🚀
View GitHub Profile
@avin
avin / tcpdump_bps.pl
Last active August 29, 2015 14:07
Show current bandwith using tcpdump
#!/usr/bin/perl
# Usage: tcpdump -i ng10 -l -e -n dst host 192.168.1.200 | ./tcpdump_bps.pl
use strict;
use warnings;
use Time::HiRes;
my $reporting_interval = 10.0; # seconds
my $bytes_this_interval = 0;
my $start_time = [Time::HiRes::gettimeofday()];
@avin
avin / filterdns.py
Last active August 29, 2015 14:07
Generate iptables rule to block incoming DNS request (Use for DNS amplification attacks)
#!/usr/bin/python
# You can also do it by hands:
# iptables -t filter -A FORWARD -p udp -m udp --dport 53 -m string --hex-string "|05|yadro|02|ru" --algo bm -j DROP
import sys
import os
if len(sys.argv) < 2:
sys.exit('Usage: %s domain.com' % sys.argv[0])
@avin
avin / dump_running_vz.sh
Created October 13, 2014 07:31
Dump running openvz containers using LVM and upload to backup server using scp
#!/bin/sh
#-------VARIABLES-------
VZLIST_CMD=/usr/sbin/vzlist
VZDUMP_CMD=/usr/sbin/vzdump
DUMP_PATH=/var/backup/vzdump/current
SCP_UPLOAD_ENABLE=0
[email protected]:/backup
@avin
avin / export_osm_to_gis
Last active August 29, 2015 14:13
Export data from OSM Rails_Port DB to PostGIS DB and reload renderd
#!/bin/bash
osmosis="/usr/local/bin/osmosis"
log="/tmp/openstreetmap2drsk_gis.log"
var_dir="/var/gis_update"
osm_new="${var_dir}/osm_new.osm"
osm_prev="${var_dir}/osm_prev.osm"
diff_api_changes="${var_dir}/diff_api_changes.osc"
need_to_render="${var_dir}/tiles_to_render.list"
# export current OSM db
@avin
avin / SpeedUpPowerShellBootup
Created March 15, 2015 12:54
Speeding Up PowerShell Startup
Set-Alias ngen (Join-Path ([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) ngen.exe)
[AppDomain]::CurrentDomain.GetAssemblies() |
sort {Split-path $_.location -leaf} |
%{
$Name = (Split-Path $_.location -leaf)
if ([System.Runtime.InteropServices.RuntimeEnvironment]::FromGlobalAccessCache($_))
{
Write-Host "Already GACed: $Name"
}else
{
@avin
avin / Object.byString.js
Created March 26, 2015 08:12
Object.byString
// Usage: Object.byString(someObj, 'part3[0].name');
// Demo: http://jsfiddle.net/alnitak/hEsys/
Object.byString = function(o, s) {
s = s.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
s = s.replace(/^\./, ''); // strip a leading dot
var a = s.split('.');
for (var i = 0, n = a.length; i < n; ++i) {
var n = a[i];
if (n in o) {
@avin
avin / isInPolygon
Created May 15, 2015 08:54
"Is point in polygon" function for leaflet
var isInPolygon = function (pointLanLng, polygon) {
var n, i, j, xi, xj, yi, yj, intersect,
inside = false,
x = pointLanLng.lat, y = pointLanLng.lng,
polygonLatLngs = polygon.getLatLngs();
for (n = 0; n < polygonLatLngs.length; n = n+1) {
for (i = 0, j = polygonLatLngs[n].length - 1; i < polygonLatLngs[n].length; j = i++) {
xi = polygonLatLngs[n][i]['lat'];
@avin
avin / search_maillog_by_email.sh
Created June 17, 2015 12:19
Search mail-chain in maillog by email
#/bin/sh
EMAIL=$1
MAILLOG_FILE=/var/log/mail/maillog
if [[ $EMAIL =~ "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+" ]]; then
cat $MAILLOG_FILE | grep $EMAIL | awk -F": " '{print $2}' | grep -v "NOQUEUE" | xargs -I{} sh -c "grep {} $MAILLOG_FILE --color=auto; echo '-----------------------'"
else
echo "Use like: mailfind [email protected]"
fi
@avin
avin / remove_old.cmd
Last active August 29, 2015 14:28
Remove oldest files in folder by total files count
@echo off
setlocal
set Folder=c:\test\oldfiles
set MaxFiles=3
set FileExt=.png
:start
dir "%Folder%\*%FileExt%" /a-d | find /c "%FileExt%" > NUMfiles.###
set /p count=<NUMfiles.###
@avin
avin / mongo_dump.sh
Created September 1, 2015 11:04
Backup mongo DB
mongodump --db elementario --out /var/mongodump/`date +%Y_%m_%d____%H_%M`