Skip to content

Instantly share code, notes, and snippets.

@jay-lannister
jay-lannister / delete-files-with-size-0.sh
Created December 12, 2014 08:13
delete files with size 0
find . -size 0 -delete
@jay-lannister
jay-lannister / Asset.sh
Created November 22, 2014 11:18
How to Flush DNS Cache in OS X Yosemite with discoveryutil
# ref: http://osxdaily.com/2014/11/20/flush-dns-cache-mac-os-x/
# Clear MDNS Cache
sudo discoveryutil mdnsflushcache
# Clear UDNS Cache
sudo discoveryutil udnsflushcaches
# Flush and Reset All DNS Caches in OS X Yosemite
ps -eF --sort -rss |head -n 5
ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 5
# 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.
@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
@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 / Show which processes are listening to which ports.sh
Created November 7, 2014 12:40
특정 포트를 사용 중인 프로세스 알아내기
lsof -i | grep LISTEN
@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 / Asset.sql
Created November 7, 2014 12:39
Where does MySQL store database files?
select @@datadir;
@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