Skip to content

Instantly share code, notes, and snippets.

@jay-lannister
jay-lannister / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jay-lannister
jay-lannister / active-threads-of-a-jvm-process.sh
Created November 5, 2014 11:38
Active thread count of a process (jvm) on linux?
ps huH p <PID_OF_U_PROCESS> | wc -l
# nlwp = number of lightweight process
ps -o nlwp <PID_OF_U_PROCESS>
@jay-lannister
jay-lannister / expand-partition-on-aws-linux.sh
Last active August 29, 2015 14:08
Linux partition management on AWS
# references
# [Resizing Root Partition on Linux in Amazon EC2](https://linuxacademy.com/blog/linux/resizing-root-partition-on-linux-in-amazon-ec2/)
# 1. create a snapshot of the old hdd
# 2. create a new volume which has a more storage than the old one from the snapshot
# 3. check the new partition name you want to expand by running
lsblk
# 4. expand the hdd on the fly
resize2fs /dev/xvde
@jay-lannister
jay-lannister / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jay-lannister
jay-lannister / Asset.sql
Created November 7, 2014 12:39
Where does MySQL store database files?
select @@datadir;
@jay-lannister
jay-lannister / find.sh
Created November 7, 2014 12:40
특정 문자열을 포함한 파일 모두 찾기
# 문자열 "mysql"이 포함된 파일을 폴더 두 군데를 뒤져서 찾는다.
#
# /System/Library/LaunchDaemons/
# /Library/LaunchDaemons/
grep mysql {,/System}/Library/LaunchDaemons/*
@jay-lannister
jay-lannister / Show which processes are listening to which ports.sh
Created November 7, 2014 12:40
특정 포트를 사용 중인 프로세스 알아내기
lsof -i | grep LISTEN
@jay-lannister
jay-lannister / kill.sh
Created November 7, 2014 12:41
프로세스 이름을 이용해 프로세스 죽이기
# http://www.howtogeek.com/howto/ubuntu/kill-a-process-by-process-name-from-ubuntu-command-line/
# http://stackoverflow.com/questions/8594653/killing-all-process-from-command-line
#
# Side note -
#
# kill -9 is overkill (no pun intended) because it prevents the killed process from running cleanup (e.g., atexit() calls, like the difference between exit and _exit). It may or may not be a problem with firefox, but in general consider trying "kill -9" only after plain "kill" fails.
# kill
@jay-lannister
jay-lannister / attach-new-hdd.sh
Created November 8, 2014 04:55
Linux partition management on AWS
fdisk -l
# CentOS 6 uses ext4 as a default filesystem
mkfs.ext4 /dev/xvdj
# CentOS 7 uses xfs as a default filesystem
mkfs.xfs /dev/xvdj
vim /etc/fstab
# Reference: http://security.stackexchange.com/questions/42618/how-to-protect-tomcat-7-against-slowloris-attack
# Use firewall rules to prevent too many connections from a single host. This will mitigate run-of-the-mill Denial of Service attacks but not distributed ones (DDoS).
# Here is an example of an iptables command which can be used to limit the number of concurrent connections that can be established to port 80 from a single client host:
iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 50 -j REJECT
# This would, however, have side-effects if many users were legitimately connecting from a single IP (e.g. mega-proxy), so the number of connections would need to be tuned reasonably - dependant on the traffic expected.