Skip to content

Instantly share code, notes, and snippets.

View makeittotop's full-sized avatar

abhishek pareek makeittotop

  • Canada
  • 11:42 (UTC -07:00)
View GitHub Profile
use test;
create table t1 ( id int not null auto_increment primary key, value varchar(20));
insert into t1 (value)
select 'ass'
union all
select 'foo'
union all
select 'bar'
union all
select count(*) from
sakila.actor;
select * from sakila.actor;
select "foo" as "boo";
select actor_id, first_name, last_name
from sakila.actor
where actor_id > 100
@makeittotop
makeittotop / gist:752a0d31e5b4a10b8468fb31ccc7f19d
Created September 5, 2016 09:20
mysql create view alter table dump
create table employees(
employee_id INT NOT NULL AUTO_INCREMENT,
employee_title VARCHAR(100) NOT NULL,
employee_author VARCHAR(40) NOT NULL,
submission_date DATE,
PRIMARY KEY ( employee_id )
);
create table titles (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
@makeittotop
makeittotop / gist:ce718e656fa8d0615f5475ba1a923c22
Created September 1, 2016 11:29
apache-webserver rewritecond with nc and l flags
The RewriteCond directive just describes an additional condition for a RewriteRule directive. So RewriteCond must always be associated with a RewriteRule.
In your case the three RewriteCond probably belong to the first RewriteRule like this:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
Now this rule is applied if the pattern of the RewriteRule matches the current request URL (per-directory path stripped before) and if the condition is fulfilled.
@makeittotop
makeittotop / gist:bb6972c4c94e157888585c66f697fef9
Last active September 1, 2016 11:34
apache webserver htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !cfn-auth-cookie=abhishekpareek; [NC]
RewriteRule ^ http://www.google.com [NC,L]
RewriteCond %{REQUEST_URI} ^/xml.*$ [NC]
RewriteRule ^.*$ - [R=404,L]
@makeittotop
makeittotop / gist:fcba879b48c1cd5fc44e0155c0440ff8
Created August 29, 2016 08:37
apache-spark-find-malicious-ips-apache-log
>>> input = sc.textFile("/vagrant/access_log-20160828")
>>> xmlrpc_attack = input.filter(lambda x: "xmlrpc.php" in x)
>>> attacking_ips=xmlrpc_attack.filter(lambda x: '12.0.1.8' not in x).map(lambda x: x.split()[0])
>>> counts = attacking_ips.map(lambda ip: (ip,1))
>>> total = counts.reduceByKey(lambda x,y : x+y)
>>> total.foreach(print)
(u'185.106.122.248', 57)
(u'163.172.149.145', 2376)
(u'89.248.174.4', 4)
(u'163.172.179.35', 741)
@makeittotop
makeittotop / gist:614f21a9dcfa501cfdf56feca2ed67a7
Last active August 28, 2016 10:27
spark count number of words per file
>>> # count word occurences in a file
>>> input.flatMap(lambda x: x.split(' ')).map(lambda x: (x,1)).reduceByKey(lambda x, y: x+y).collect()
[(u'', 68), (u'when', 1), (u'R,', 1), (u'including', 3), (u'computation', 1), (u'using:', 1), (u'guidance', 2), (u'Scala,', 1), (u'environment', 1), (u'only', 1), (u'rich', 1), (u'Apache', 1), (u'sc.parallelize(range(1000)).count()', 1), (u'Building', 1), (u'And', 1), (u'guide,', 1), (u'return', 2), (u'Please', 3), (u'[Eclipse](https://cwiki.apache.org/confluence/display/SPARK/Useful+Developer+Tools#UsefulDeveloperTools-Eclipse)', 1), (u'Try', 1), (u'not', 1), (u'Spark', 15), (u'scala>', 1), (u'Note', 1), (u'cluster.', 1), (u'./bin/pyspark', 1), (u'params', 1), (u'through', 1), (u'GraphX', 1), (u'[run', 1), (u'abbreviated', 1), (u'For', 3), (u'##', 8), (u'library', 1), (u'see', 3), (u'"local"', 1), (u'[Apache', 1), (u'will', 1), (u'#', 1), (u'processing,', 1), (u'for', 11), (u'[building', 1), (u'Maven', 1), (u'["Parallel', 1), (u'provides', 1), (u'print', 1), (u'suppor
w uses the access time of the tty to determine how idle someone is, this is covered in idletime()
which stats the tty file and subtracts its atime from the current time. pkill can use a terminal as the filter
to kill processes.
So, you want to kill anyone who isn't root and idle for over 5 minutes?
for t in `w -h | grep -v '^root' | awk '{print $2}'`; do find /dev/$t -amin +5 -exec pkill -t $t \; ; done
What is going on here:
Use w with no headers to find all users
@makeittotop
makeittotop / examentool.sh
Last active August 22, 2016 07:50 — forked from benbridts/examentool.sh
Examentool on fedora
##############
# xprintidle #
##############
# install xprintidle dependencies
sudo yum -y install libXScrnSaver-devel libX11-devel
# download xprintidle source
wget https://launchpad.net/ubuntu/+archive/primary/+files/xprintidle_0.2.orig.tar.gz
# extract
tar -xf xprintidle_0.2.orig.tar.gz
cd xprintidle-0.2/
@makeittotop
makeittotop / Makefile
Created August 11, 2016 08:20 — forked from llj098/Makefile
a sample tcp server runs in kernel
obj-m += tcp_svr_sample.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clea