├── .gitignore ├── HOME ├── .ammonite │ ├── README.md │ └── predef.sc ├── .bash_aliases └── .zsh_aliases ├── README.md ├── SSD ├── README.md └── etc │ └── rc.local ├── Scala ├── .ammonite │ └── predef.sc ├── README.md └── install-scala.sh ├── Vim └── README.md ├── archive └── README.md ├── dot-files ├── README.md └── zsh │ ├── .my-docker-common │ ├── .my-git-common │ └── .my-shell-common ├── other └── gitignore_files │ ├── eclipse_java_spring │ └── .gitignore │ └── eclipse_scala_play │ └── .gitignore ├── scripts ├── README-kr.md ├── README.md ├── String.md ├── backup-mysql-db.sh ├── ps-killer.sh ├── setup-scala.sh ├── tomcat-run.sh └── zsh │ ├── iterm2-how-to-use-ligatures.png │ ├── osx-terminal-change-font-to-powerline.png │ └── zsh-installation.md └── tmux └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | 3 | .idea -------------------------------------------------------------------------------- /HOME/.ammonite/README.md: -------------------------------------------------------------------------------- 1 | Ammonite REPL 2 | ============= 3 | The [Ammonite-REPL](http://ammonite.io/#Ammonite-REPL) is an improved Scala REPL. 4 | 5 | After install it, copy the [`predef.sc`](predef.sc) to the `~/.ammonite` folder. 6 | 7 | 8 | -------------------------------------------------------------------------------- /HOME/.ammonite/predef.sc: -------------------------------------------------------------------------------- 1 | println(s"Hello ${sys.env.get("MY_NAME").orElse(sys.env.get("USER")).getOrElse("User")}!") 2 | 3 | def encodeToUnicode(x: String): String = x.map(c => "\\u%04x".format(c.toInt)).mkString 4 | 5 | implicit class ToUnicode(val x: String) extends AnyVal { 6 | def encodeToUnicode: String = x.map(c => "\\u%04x".format(c.toInt)).mkString 7 | } 8 | 9 | implicit class BinaryToIntOrLong(private val sc: StringContext) extends AnyVal { 10 | def b(args: Any*): Int = Integer.parseInt(sc.parts.mkString.replaceAllLiterally("_", ""), 2) 11 | def B(args: Any*): Long = java.lang.Long.parseLong(sc.parts.mkString.replaceAllLiterally("_", ""), 2) 12 | } 13 | 14 | def printHelp(name: String, help: => Unit): Unit = { 15 | println( 16 | s"""======================== 17 | |To use $name, do 18 | |""".stripMargin 19 | ) 20 | help 21 | } 22 | 23 | def printLoadInfo(name: String, version: String, methodName: String): Unit = 24 | println( 25 | s"""============================= 26 | |Loading $name - $version 27 | |----------------------------- 28 | |NOTE: 29 | |To specify the version, run 30 | | $methodName("YOUR_VERSION") 31 | | 32 | |e.g.) 33 | |$methodName("$version") 34 | |""".stripMargin 35 | ) 36 | 37 | object DefaultVersions { 38 | /* updated: 2018-03-03 */ 39 | val Scalaz = "7.2.20" 40 | val BetterFile = "3.4.0" 41 | val FastParse = "1.0.0" 42 | val PlayJson = "2.6.9" 43 | } 44 | 45 | def printDefaultVersions: Unit = { 46 | import scala.reflect.runtime.{universe => ru} 47 | val mirror = ru.runtimeMirror(getClass.getClassLoader) 48 | 49 | val moduleSymbol = ru.typeOf[DefaultVersions.type].termSymbol.asModule 50 | val moduleMirror = mirror.reflectModule(moduleSymbol) 51 | val instanceMirror = mirror.reflect(moduleMirror.instance) 52 | 53 | val fields = moduleSymbol.typeSignature.declarations.filter(_.asTerm.isVal) 54 | val stringBuilder = new StringBuilder 55 | stringBuilder ++= s"""====================== 56 | | Default Versions 57 | |---------------------- 58 | |""".stripMargin 59 | val max = fields.map(_.name.toString.trim.length).max 60 | for (f <- fields) { 61 | val fieldMirror = instanceMirror.reflectField(f.asTerm) 62 | val fieldName = f.name.toString.trim 63 | stringBuilder ++= s"${" " * (max - fieldName.length)}${fieldName}: ${fieldMirror.get}\n" 64 | } 65 | println(stringBuilder ++= "======================") 66 | } 67 | 68 | 69 | def scalazLib(version: String) = "org.scalaz" %% "scalaz-core" % version 70 | def betterFileLib(version: String) = "com.github.pathikrit" %% "better-files" % version 71 | def fastParseLib(version: String) = "com.lihaoyi" %% "fastparse" % version 72 | def playJsonLib(version: String) = "com.typesafe.play" %% "play-json" % version 73 | 74 | import coursier.ivy 75 | 76 | def addIvyRepo(url: String): Unit = interp.repositories() ++= Seq(ivy.IvyRepository.fromPattern( 77 | url +: ivy.Pattern.default 78 | )) 79 | 80 | 81 | import coursier.MavenRepository 82 | import coursier.core.Authentication 83 | 84 | def addMavenRepo(url: String, auth: Option[Authentication]): Unit = interp.repositories() ++= Seq(MavenRepository( 85 | url, 86 | authentication = auth 87 | )) 88 | 89 | 90 | def loadDependency(coordinate: coursier.Dependency): Unit = interp.load.ivy(coordinate) 91 | 92 | def loadDependencies(coordinates: coursier.Dependency*): Unit = interp.load.ivy(coordinates:_*) 93 | 94 | def loadPlayJson(version: String = DefaultVersions.PlayJson): Unit = { 95 | printLoadInfo("Play-Json", version, "loadPlayJson") 96 | interp.load.ivy(playJsonLib(version)) 97 | printHelp("Play-Json", helpPlayJson) 98 | } 99 | def loadPlayJson: Unit = loadPlayJson(DefaultVersions.PlayJson) 100 | 101 | def helpPlayJson: Unit = println( 102 | """--- 103 | |import play.api.libs.json._ 104 | |--- 105 | |""".stripMargin 106 | ) 107 | 108 | def loadScalaz(version: String = DefaultVersions.Scalaz): Unit = { 109 | printLoadInfo("Scalaz", version, "loadScalaz") 110 | interp.load.ivy(scalazLib(version)) 111 | printHelp("Scalaz", helpScalaz) 112 | } 113 | def loadScalaz: Unit = loadScalaz(DefaultVersions.Scalaz) 114 | 115 | def helpScalaz: Unit = println( 116 | """--- 117 | |import scalaz._ 118 | |import Scalaz._ 119 | |--- 120 | |""".stripMargin 121 | ) 122 | 123 | def loadBetterFile(version: String = DefaultVersions.BetterFile): Unit = { 124 | printLoadInfo("BetterFile", version, "loadBetterFile") 125 | interp.load.ivy(betterFileLib(version)) 126 | printHelp("better-files", helpBetterFile) 127 | } 128 | def loadBetterFile: Unit = loadBetterFile(DefaultVersions.BetterFile) 129 | 130 | def helpBetterFile: Unit = println( 131 | """--- 132 | |import better.files._ 133 | |import java.io.{File => JFile} 134 | | 135 | |import better.files.Dsl._ 136 | |--- 137 | |""".stripMargin 138 | ) 139 | 140 | def loadFastParse(version: String = DefaultVersions.FastParse): Unit = { 141 | printLoadInfo("FastParse", version, "loadFastParse") 142 | interp.load.ivy(fastParseLib(version)) 143 | printHelp("fastparse", helpFastParse) 144 | } 145 | def loadFastParse: Unit = loadFastParse(DefaultVersions.FastParse) 146 | 147 | def helpFastParse: Unit = println( 148 | """--- 149 | |import fastparse.all._ 150 | |--- 151 | |""".stripMargin 152 | ) 153 | -------------------------------------------------------------------------------- /HOME/.bash_aliases: -------------------------------------------------------------------------------- 1 | export JAVA_HOME=/usr/lib/jvm/java-7-openjdk 2 | 3 | alias ls='ls -G' 4 | 5 | alias sshnp='ssh -o PubkeyAuthentication=no' 6 | alias scpnp='scp -o PubkeyAuthentication=no' 7 | alias ssh-p='ssh -p' 8 | alias scp-p='scp -P' 9 | 10 | alias update='sudo apt-get update' 11 | alias upgrade='sudo apt-get upgrade' 12 | alias download4upgrade='sudo apt-get -d upgrade' 13 | alias install='sudo apt-get install' 14 | alias remove='sudo apt-get remove' 15 | alias purge='sudo apt-get purge' 16 | 17 | alias psflash='ps aux | grep flash | grep -v grep | awk "{ print \$2; }"' 18 | alias killflash='kill -9 `ps aux | grep flash | grep -v grep | awk "{ print \\$2; }"`' 19 | # alias killflash="kill -9 \`ps aux | grep flash | grep -v grep | awk '{ print \$2; }'\`" 20 | 21 | alias psaux='ps aux | grep -v "grep --color=auto" | grep' 22 | alias psjava='ps aux | grep -v grep | grep java' 23 | 24 | alias du-mbs='du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[M]" | sort -n' 25 | alias du-gbs='du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[G]" | sort -n' 26 | 27 | alias ss-ls='ss -lpnt' 28 | 29 | alias gitlog='git log --decorate=full --graph' 30 | alias gitlogfull='git log --decorate=full --graph --pretty=fuller' 31 | alias gittotallines='git ls-files | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;" | xargs wc -l' 32 | 33 | alias git-push-remote-add='git remote set-url origin --add' 34 | alias git-pull-remote-add='git remote add' 35 | 36 | alias git-checkout-from-multiple-remote-repos='echo -e "\ngit checkout -b /\n e.g.)\n git checkout -b some-branch origin/some-branch\n"' 37 | alias git-pull-branch-without-checkout='echo -e "\n\e[0;31mWARNING: only for fast-forward\e[m\n\ngit fetch :\n e.g.)\n git fetch origin master:master\n"' 38 | 39 | alias ngx='sudo /etc/init.d/nginx' 40 | 41 | alias tomcatlog='tail -f -n 200 /path/to/TOMCAT_HOME/logs/catalina.out' 42 | alias tomcat='sudo /etc/init.d/tomcat' 43 | alias ap2='sudo /etc/init.d/apache2' 44 | 45 | alias setup-scala='sudo ~/Documents/my-scripts/setup-scala.sh' 46 | 47 | gitpullall() 48 | { 49 | repos_to_ignore="origin" 50 | should_ignore=-1 51 | 52 | echo "running: git pull" 53 | git pull 54 | echo "" 55 | 56 | for remote in `git remote` 57 | do 58 | echo "==================================" 59 | echo "Remote: $remote" 60 | echo "----------------------------------" 61 | for ignore in $repos_to_ignore 62 | do 63 | [ "$remote" == "$ignore" ] && { should_ignore=1; break; } || : 64 | done 65 | 66 | if [ "$should_ignore" == "-1" ] 67 | then 68 | THIS_BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` 69 | git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME$" 2>&1 > /dev/null || git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME""[[:space:]]\+" 2>&1 > /dev/null || { 70 | echo "No info of the remote repo named '$remote' is found." 71 | echo "So $remote will be fetched." 72 | echo "running: git fetch $remote" 73 | git fetch "$remote" 74 | echo "" 75 | } 76 | if git branch -r | grep -sw "$remote/$THIS_BRANCH_NAME" 2>&1 > /dev/null ; then 77 | echo "running: git pull $remote $THIS_BRANCH_NAME" 78 | git pull "$remote" "$THIS_BRANCH_NAME" 79 | else 80 | echo "$THIS_BRANCH_NAME branch does not exist on the remote called '$remote'." 81 | echo "So $remote will not be pulled from $remote." 82 | fi 83 | else 84 | echo "$remote is on the ignored list so ignore it." 85 | echo "Ignored: $remote" 86 | fi 87 | should_ignore=-1 88 | echo "==================================" 89 | echo "" 90 | done 91 | } 92 | 93 | search_file() { 94 | if [ ! -n "$1" ] 95 | then 96 | echo "Please enter a word to search" 97 | exit 98 | fi 99 | for file in `find . -type f`; do grep -H "$1" $file; done 100 | } 101 | 102 | 103 | PS1="\n\[\e[30;1m\]\[\016\]-\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n-(\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\])\n\[\e[0m\]$ " 104 | 105 | PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' 106 | -------------------------------------------------------------------------------- /HOME/.zsh_aliases: -------------------------------------------------------------------------------- 1 | # enable color support of ls and also add handy aliases 2 | if [ -x /usr/bin/dircolors ]; then 3 | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" 4 | alias ls='ls --color=auto' 5 | #alias dir='dir --color=auto' 6 | #alias vdir='vdir --color=auto' 7 | 8 | alias grep='grep --color=auto' 9 | alias fgrep='fgrep --color=auto' 10 | alias egrep='egrep --color=auto' 11 | fi 12 | 13 | 14 | setopt NO_HUP 15 | 16 | alias sudos='sudo -s' 17 | 18 | alias sshnp='ssh -o PubkeyAuthentication=no' 19 | alias scpnp='scp -o PubkeyAuthentication=no' 20 | alias ssh-p='ssh -p' 21 | alias scp-p='scp -P' 22 | 23 | alias update='sudo apt-get update' 24 | alias upgrade='sudo apt-get upgrade' 25 | alias download4upgrade='sudo apt-get -d upgrade' 26 | alias install='sudo apt-get install' 27 | alias remove='sudo apt-get remove' 28 | alias purge='sudo apt-get purge' 29 | 30 | alias psaux='ps aux | grep -v "grep --color=auto" | grep' 31 | alias psflash='ps aux | grep flash | grep -v grep | awk "{ print \$2; }"' 32 | alias killflash='kill -9 `ps aux | grep flash | grep -v grep | awk "{ print \\$2; }"`' 33 | # alias killflash="kill -9 \`ps aux | grep flash | grep -v grep | awk '{ print \$2; }'\`" 34 | 35 | alias du-mbs='du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[M]" | sort -n' 36 | alias du-gbs='du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[G]" | sort -n' 37 | 38 | alias psjava='ps aux | grep -v grep | grep java' 39 | 40 | alias ss-ls='ss -lpnt' 41 | 42 | ## Git { 43 | 44 | alias gitlog='git log --decorate=full --graph' 45 | alias gitlogfull='git log --all --decorate=full --graph --pretty=fuller' 46 | alias gittotallines='git ls-files | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;" | xargs wc -l' 47 | 48 | alias git-push-remote-add='git remote set-url origin --add' 49 | alias git-pull-remote-add='git remote add' 50 | 51 | alias git-checkout-from-multiple-remote-repos='echo -e "\ngit checkout -b /\n e.g.)\n git checkout -b some-branch origin/some-branch\n"' 52 | alias git-pull-branch-without-checkout='echo -e "\n\e[0;31mWARNING: only for fast-forward\e[m\n\ngit fetch :\n e.g.)\n git fetch origin master:master\n"' 53 | 54 | gitpullall() 55 | { 56 | repos_to_ignore="origin" 57 | should_ignore=-1 58 | 59 | echo "running: git pull" 60 | git pull 61 | echo "" 62 | 63 | for remote in `git remote` 64 | do 65 | echo "==================================" 66 | echo "Remote: $remote" 67 | echo "----------------------------------" 68 | for ignore in $repos_to_ignore 69 | do 70 | [ "$remote" = "$ignore" ] && { should_ignore=1; break; } || : 71 | done 72 | 73 | if [ "$should_ignore" = "-1" ] 74 | then 75 | THIS_BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` 76 | { git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME$" 2>&1 > /dev/null } || { git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME""[[:space:]]\+" 2>&1 > /dev/null } || { 77 | echo "No info of the remote repo named '$remote' is found." 78 | echo "So $remote will be fetched." 79 | echo "running: git fetch $remote" 80 | git fetch "$remote" 81 | echo "" 82 | } 83 | if git branch -r | grep -sw "$remote/$THIS_BRANCH_NAME" 2>&1 > /dev/null ; then 84 | echo "running: git pull $remote $THIS_BRANCH_NAME" 85 | git pull "$remote" "$THIS_BRANCH_NAME" 86 | else 87 | echo "$THIS_BRANCH_NAME branch does not exist on the remote called '$remote'." 88 | echo "So $remote will not be pulled from $remote." 89 | fi 90 | else 91 | echo "$remote is on the ignored list so ignore it." 92 | echo "Ignored: $remote" 93 | fi 94 | should_ignore=-1 95 | echo "==================================" 96 | echo "" 97 | done 98 | } 99 | 100 | ## } Git 101 | 102 | alias ngx='sudo /etc/init.d/nginx' 103 | 104 | alias tomcatlog='tail -f -n 200 /path/to/TOMCAT_HOME/logs/catalina.out' 105 | alias tomcat='sudo /etc/init.d/tomcat' 106 | 107 | search_file() { 108 | if [ ! -n "$1" ] 109 | then 110 | echo "Please enter a word to search" 111 | exit 112 | fi 113 | for file in `find . -type f`; do grep -H "$1" $file; done 114 | } 115 | 116 | 117 | export JDK6_HOME=/usr/lib/jvm/java-6-openjdk 118 | export JDK7_HOME=/usr/lib/jvm/java-7-openjdk 119 | export JDK8_HOME=/usr/lib/jvm/java-8-oracle 120 | 121 | export JAVA_HOME="$JDK8_HOME" 122 | 123 | alias jdk6='export JAVA_HOME=$JDK6_HOME' 124 | alias jdk7='export JAVA_HOME=$JDK7_HOME' 125 | alias jdk8='export JAVA_HOME=$JDK8_HOME' 126 | 127 | 128 | PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | for-linux 2 | ========= 3 | 4 | Scripts and tips for Linux users. These are mostly for Ubuntu/Debian Linux, yet there should be something equivalent or similar in the other Linux distributions. 5 | -------------------------------------------------------------------------------- /SSD/README.md: -------------------------------------------------------------------------------- 1 | SSD 2 | === 3 | 4 | ## fstab 5 | 6 | 7 | ## Using rc.local 8 | Add the folloing lines to the `/etc/rc.local` file. 9 | ```shell 10 | LOG=/var/log/trim.log 11 | 12 | echo "*** rc.local: $(date -R) ***" >> $LOG 13 | fstrim -v / >> $LOG 14 | echo "" >> $LOG 15 | ``` 16 | -------------------------------------------------------------------------------- /SSD/etc/rc.local: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | # 3 | # rc.local 4 | # 5 | # This script is executed at the end of each multiuser runlevel. 6 | # Make sure that the script will "exit 0" on success or any other 7 | # value on error. 8 | # 9 | # In order to enable or disable this script just change the execution 10 | # bits. 11 | # 12 | # By default this script does nothing. 13 | 14 | LOG=/var/log/trim.log 15 | 16 | echo "*** rc.local ***" >> $LOG 17 | echo "*** $(date -R) ***" >> $LOG 18 | fstrim -v / >> $LOG 19 | echo "" >> $LOG 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /Scala/.ammonite/predef.sc: -------------------------------------------------------------------------------- 1 | println(s"Hello ${sys.env.get("MY_NAME").orElse(sys.env.get("USER")).getOrElse("User")}!") 2 | 3 | def encodeToUnicode(x: String): String = x.map(c => "\\u%04x".format(c.toInt)).mkString 4 | 5 | implicit final class ToUnicode(private val x: String) extends AnyVal { 6 | def encodeToUnicode: String = x.map(c => "\\u%04x".format(c.toInt)).mkString 7 | } 8 | 9 | implicit class IntLiteral(private val sc: StringContext) extends AnyVal { 10 | def i(args: Any*): Int = Integer.parseInt(sc.parts.mkString.replaceAllLiterally("_", ""), 10) 11 | } 12 | 13 | implicit class LongLiteral(private val sc: StringContext) extends AnyVal { 14 | def l(args: Any*): Long = sc.parts.mkString.replaceAllLiterally("_", "").toLong 15 | } 16 | 17 | implicit class BigIntLiteral(private val sc: StringContext) extends AnyVal { 18 | def bi(args: Any*): BigInt = BigInt(sc.parts.mkString.replaceAllLiterally("_", "")) 19 | } 20 | 21 | implicit class BinaryToIntOrLong(private val sc: StringContext) extends AnyVal { 22 | def b(args: Any*): Int = Integer.parseInt(sc.parts.mkString.replaceAllLiterally("_", ""), 2) 23 | def B(args: Any*): Long = java.lang.Long.parseLong(sc.parts.mkString.replaceAllLiterally("_", ""), 2) 24 | } 25 | 26 | def toHexBinaryString(data: Seq[Byte]): String = { 27 | val hexCode = "0123456789ABCDEF" 28 | data.foldLeft(List.empty[Char]) { (acc, b) => 29 | hexCode(b & 15) :: hexCode(b >> 4 & 15) :: acc 30 | }.reverse.mkString 31 | } 32 | 33 | def epochSecondToSydneyDateTime(epochSecond: Long): java.time.ZonedDateTime = 34 | java.time.Instant.ofEpochSecond(epochSecond).atZone(java.time.ZoneId.of("Australia/Sydney")) 35 | 36 | import scala.reflect._ 37 | import scala.reflect.runtime.universe._ 38 | def printVals[A: TypeTag](valueProcess: Any => String): Unit = { 39 | import scala.reflect.runtime.{universe => ru} 40 | val mirror = ru.runtimeMirror(getClass.getClassLoader) 41 | 42 | val theType = ru.typeOf[A] 43 | val moduleSymbol = theType.termSymbol.asModule 44 | val moduleMirror = mirror.reflectModule(moduleSymbol) 45 | val instanceMirror = mirror.reflect(moduleMirror.instance) 46 | 47 | val fields = moduleSymbol.typeSignature.declarations.filter(_.asTerm.isVal) 48 | val max = fields.map(_.name.toString.trim.length).max 49 | val fieldNamesAndValues = for { 50 | f <- fields 51 | fieldMirror = instanceMirror.reflectField(f.asTerm) 52 | fieldName = f.name.toString.trim 53 | } yield s"${" " * (max - fieldName.length)}${fieldName}: ${valueProcess(fieldMirror.get)}" 54 | 55 | val typeName = { 56 | val typeNameSplit = theType.toString.split("\\.") 57 | val lastTwo = typeNameSplit.drop(typeNameSplit.length - 2) 58 | if (lastTwo.last == "type") lastTwo.head else lastTwo.last 59 | } 60 | 61 | val maxLength = fieldNamesAndValues 62 | .map(_.length) 63 | .foldLeft(0)((max, length) => if (length > max) length else max) 64 | val length = Some(s" $typeName".length).filter(_ > maxLength).getOrElse(maxLength) 65 | 66 | println( 67 | fieldNamesAndValues.mkString( 68 | s"""${"=" * length} 69 | | $typeName 70 | |${"-" * length} 71 | |""".stripMargin, 72 | "\n", 73 | s"\n${"=" * length}" 74 | ) 75 | ) 76 | } 77 | -------------------------------------------------------------------------------- /Scala/README.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | > NOTE: Outdated 4 | > 5 | > Use [Coursier](https://get-coursier.io) to install Scala instead. 6 | 7 | ## Scala and SBT on Ubuntu 8 | * Just run the following command and it will download and install Scala and SBT. The version will be installed is specified in the `install-scala.sh` script file (It will be probably changed to fetch the latest version automatically later on). 9 | 10 | ```shell 11 | curl -Lo- https://goo.gl/lYN6xn | bash 12 | ``` 13 | -------------------------------------------------------------------------------- /Scala/install-scala.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################### 3 | ## Script to install Scala and SBT ## 4 | ## ## 5 | ## @author Lee, SeongHyun (Kevin) ## 6 | ## @veraion 0.0.1 (2015-03-22) ## 7 | ## ## 8 | ## http://lckymn.com ## 9 | ############################################### 10 | 11 | SCALA_VERSION="2.11.8" 12 | SBT_VERSION="0.13.9" 13 | 14 | # sudo apt-get remove scala-library scala 15 | 16 | TMP_DIR="/tmp/scala-install-tmp-`date +%s`" 17 | 18 | echo "mkdir -p $TMP_DIR" 19 | mkdir -p "$TMP_DIR" 20 | echo "cd $TMP_DIR" 21 | cd "$TMP_DIR" 22 | echo "=============================" 23 | echo "Download Scala" 24 | echo "-----------------------------" 25 | echo "" 26 | echo "wget http://www.scala-lang.org/files/archive/scala-$SCALA_VERSION.deb" 27 | wget "http://www.scala-lang.org/files/archive/scala-$SCALA_VERSION.deb" 28 | echo "" 29 | echo "-----------------------------" 30 | echo "Downloading Scala: Done" 31 | echo "=============================" 32 | echo "" 33 | echo "=============================" 34 | echo "Download SBT" 35 | echo "-----------------------------" 36 | echo "wget http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb " 37 | wget "http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb" 38 | echo "" 39 | echo "-----------------------------" 40 | echo "Downloading SBT: Done" 41 | echo "=============================" 42 | echo "" 43 | echo "sudo apt-get update " 44 | sudo apt-get update 45 | echo "" 46 | echo "=============================" 47 | echo "Install Scala" 48 | echo "-----------------------------" 49 | echo "" 50 | echo "sudo dpkg -i scala-$SCALA_VERSION.deb " 51 | sudo dpkg -i "scala-$SCALA_VERSION.deb" 52 | echo "" 53 | echo "-----------------------------" 54 | echo "Scala installation: Done" 55 | echo "=============================" 56 | echo "" 57 | echo "=============================" 58 | echo "Install SBT" 59 | echo "-----------------------------" 60 | echo "" 61 | echo "sudo dpkg -i sbt-$SBT_VERSION.deb " 62 | sudo dpkg -i "sbt-$SBT_VERSION.deb" 63 | echo "" 64 | echo "-----------------------------" 65 | echo "SBT installation: Done" 66 | echo "=============================" 67 | echo "" 68 | 69 | echo "" 70 | echo "Remove the temporary directory." 71 | echo "rm -R $TMP_DIR" 72 | rm -R "$TMP_DIR" 73 | echo "" 74 | -------------------------------------------------------------------------------- /Vim/README.md: -------------------------------------------------------------------------------- 1 | # Vim 2 | 3 | ## Change Color Theme 4 | ### Solarized 5 | * Get [vim-colors-solarized](https://github.com/altercation/vim-colors-solarized "vim-colors-solarized"). 6 | * Install (Create the folder, `~/.vim/colors/`, if doesn't exist). 7 | 8 | ```shell 9 | $ cp colors/solarized.vim ~/.vim/colors/ 10 | ``` 11 | * Edit `/etc/vim/vimrc` or `/etc/vim/vimrc.local` or `~/.vimrc` 12 | 13 | ```shell 14 | " if has('gui_running') 15 | " set background=light 16 | " else 17 | " set background=dark 18 | " endif 19 | set t_Co=16 20 | let g:solarized_termcolors=16 21 | colorscheme solarized 22 | ``` 23 | 24 | ### Monokai 25 | * Get [vim-monokai](https://github.com/sickill/vim-monokai "vim-monokai"). 26 | * Install 27 | 28 | ```shell 29 | $ cp colors/Monokai.vim ~/.vim/colors/ 30 | ``` 31 | * Edit `/etc/vim/vimrc` or `/etc/vim/vimrc.local` or `~/.vimrc` 32 | 33 | ```shell 34 | set t_Co=256 35 | colorscheme Monokai 36 | ``` 37 | 38 | ### Molokai 39 | * Get [molokai](https://github.com/tomasr/molokai "molokai"). 40 | * Install 41 | 42 | ```shell 43 | $ cp colors/molokai.vim ~/.vim/colors/ 44 | ``` 45 | * Edit `/etc/vim/vimrc` or `/etc/vim/vimrc.local` or `~/.vimrc` 46 | 47 | ```shell 48 | set t_Co=256 49 | colorscheme molokai 50 | ``` 51 | 52 | # GVim 53 | ## Intall GVim 54 | 55 | ```shell 56 | $ apt-get install vim-gnome 57 | ``` 58 | 59 | ## Change Color Theme 60 | ### Solarized 61 | * Install it (Check out [Solarized for Vim](#solarized)) 62 | * Edit `/etc/vim/gvimrc` or `/etc/vim/gvimrc.local` or `~/.gvimrc` 63 | 64 | ```shell 65 | colorscheme solarized 66 | ``` 67 | 68 | ### Monokai 69 | * Install it (Check out [Monokai for Monokai](#monokai)) 70 | * Edit `/etc/vim/gvimrc` or `/etc/vim/gvimrc.local` or `~/.gvimrc` 71 | 72 | ```shell 73 | colorscheme Monokai 74 | ``` 75 | 76 | ### Molokai 77 | * Install it (Check out [Molokai for Vim](#molokai)) 78 | * Edit `/etc/vim/gvimrc` or `/etc/vim/gvimrc.local` or `~/.gvimrc` 79 | 80 | ```shell 81 | colorscheme molokai 82 | ``` 83 | 84 | ## Change Key Binding 85 | ### Using Ctrl+C / Ctrl+X / Ctrl+V for Copy, Cut and Paste 86 | * Edit `/etc/vim/gvimrc` or `/etc/vim/gvimrc.local` or `~/.gvimrc` 87 | 88 | ``` 89 | vmap "+yi 90 | vmap "+c 91 | vmap c"+p 92 | imap + 93 | 94 | ``` 95 | 96 | ## Change Default Font 97 | 1. Open GVim 98 | 2. Edit -> 'Select Font' -> Choose the font you want to use. 99 | 3. : -> `set gfn` -> It will give the current font name and size. 100 | 4. Edit `/etc/vim/gvimrc` or `/etc/vim/gvimrc.local` or `~/.gvimrc` 101 | 5. Use the font name got from `set gfn` 102 | 103 | e.g.) If `set gfn` gives, `Monaco 11` 104 | 105 | ```shell 106 | set gfn=Monaco\ 11 107 | ``` 108 | 109 | ## Change Tab Size 110 | 1. Open `/etc/vim/vimrc` or `/etc/vim/vimrc.local` or `~/.vimrc` 111 | 2. Add the following line 112 | 113 | ``` 114 | set tabstop=SIZE 115 | ``` 116 | e.g.) 117 | ``` 118 | set tabstop=2 119 | ``` 120 | 121 | -------------------------------------------------------------------------------- /archive/README.md: -------------------------------------------------------------------------------- 1 | # Create and Split Tar File into Several Files 2 | ## There are many large files to be archived and split 3 | * create archives 4 | 5 | ```shell 6 | $ tar cz large_file_1 large_file_2 | split -b 1024MiB - result_files.tgz_ 7 | ``` 8 | 9 | * uncompress 10 | 11 | ```shell 12 | $ cat result_files.tgz_* | tar xz 13 | ``` 14 | 15 | * This solution avoids the need to use an intermediate large file when (de)compressing. 16 | * Use the tar -C option to specify a different directory for the resulting files. 17 | 18 | 19 | ## There is one large file to be archived and split 20 | * If only one file needs to be split, tar with a single source file is still fine but in this case, gzip can be used as well. 21 | 22 | * create archives 23 | 24 | ```shell 25 | $ gzip -c one_large_file | split -b 1024MiB - result_files.gz_ 26 | ``` 27 | 28 | * uncompress 29 | 30 | ```shell 31 | $ cat result_files.gz_* | gunzip -c > one_large_file 32 | ``` 33 | -------------------------------------------------------------------------------- /dot-files/README.md: -------------------------------------------------------------------------------- 1 | # Common Dot Files 2 | 3 | ## For Docker, 4 | 5 | Add following lines to `.bashrc` or `.zshrc`. 6 | 7 | **Currently it's only for z-shell** 8 | 9 | ```shell 10 | if [ -f ~/dot-files/zsh/.my-docker-common ]; then 11 | . ~/dot-files/zsh/.my-docker-common 12 | fi 13 | ``` 14 | 15 | Now you can do 16 | ```shell 17 | # Stop all running processes 18 | dk-stop-all 19 | 20 | # Clean all stopped processes 21 | dk-clean-ps 22 | 23 | # Clean all dangling images 24 | dk-clean-images 25 | 26 | # Clean all iamges 27 | dk-clean-images-all 28 | 29 | # Print Docker version info including Docker Machine's and Docker Compose's 30 | dk-versions 31 | 32 | # Get Docker container IP 33 | dk-ip CONTAINER_ID 34 | e.g.) dk-ip 33dc22bb443c 35 | 36 | ``` 37 | -------------------------------------------------------------------------------- /dot-files/zsh/.my-docker-common: -------------------------------------------------------------------------------- 1 | alias dk-versions='echo -e "\e[34mDocker version:\e[0m"; docker --version; echo -e "\n\e[34mDocker Compose version:\e[0m"; docker-compose --version; echo -e "\n\e[34mDocker Machine version:\e[0m"; docker-machine --version; echo ""' 2 | 3 | # Docker { 4 | 5 | # For Mac OS X 6 | alias dk-data='cd ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux' 7 | 8 | alias dk='docker' 9 | 10 | alias dk-dangling='docker images --filter dangling=true' 11 | 12 | alias dk-stop-all='docker stop $(docker ps -q)' 13 | alias dk-clean-images='docker rmi $(docker images -a --filter=dangling=true -q)' 14 | alias dk-clean-images-all='docker rmi $(docker images -a -q)' 15 | alias dk-clean-ps='docker rm $(docker ps --filter=status=exited --filter=status=created -q)' 16 | 17 | dk-ip() { 18 | docker inspect --format '{{ .NetworkSettings.IPAddress }}' $@ || echo -e '\n\e[31m[error] Please enter container ID\e[0m\ne.g.)\n$ \e[32mdk-ip 33dc22bb443c\n\e[0m' 19 | } 20 | 21 | dk-bash-to() { 22 | docker exec -i -t "$@" /bin/bash 23 | } 24 | 25 | 26 | # } Docker 27 | 28 | 29 | # Docker Machine { 30 | alias dkm='docker-machine' 31 | 32 | alias dkm-init='docker-machine create --driver virtualbox default' 33 | 34 | # } Docker Machine 35 | 36 | 37 | # Docker Compose { 38 | 39 | alias dkc='docker-compose' 40 | 41 | # } Docker Compose 42 | -------------------------------------------------------------------------------- /dot-files/zsh/.my-git-common: -------------------------------------------------------------------------------- 1 | 2 | ## Git { 3 | 4 | alias gitlog='git log --decorate=full --graph --stat' 5 | alias gitlogfull='git log --decorate=full --graph --pretty=fuller --stat' 6 | alias gittotallines='git ls-files | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;" | xargs wc -l' 7 | 8 | alias git-push-remote-add='git remote set-url origin --add' 9 | alias git-pull-remote-add='git remote add' 10 | 11 | alias git-checkout-from-multiple-remote-repos='echo -e "\ngit checkout -b /\n e.g.)\n git checkout -b some-branch origin/some-branch\n"' 12 | alias git-pull-branch-without-checkout='echo -e "\n\e[0;31mWARNING: only for fast-forward\e[m\n\ngit fetch :\n e.g.)\n git fetch origin master:master\n"' 13 | 14 | alias git-sync-remote-branches='git fetch --prune origin "+refs/tags/*:refs/tags/*"' 15 | 16 | alias git-add-upstream='git remote add upstream' 17 | 18 | alias git-rm-all-indexed='git ls-files -z | xargs -0 git rm --cached' 19 | 20 | alias git-ignore-case='git config --global core.ignorecase' 21 | 22 | alias git-clean-up-local-branches='git fetch --prune && git branch -r | awk '"'"'{print $1}'"'"' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '"'"'{print $1}'"'"' | xargs git branch -d' 23 | 24 | alias git-head-commit-id='git rev-parse HEAD' 25 | 26 | alias git-fixup='git commit --fixup' 27 | 28 | # alias git-fixup-head='git-fixup "$(git-head-commit-id)"' 29 | alias git-fixup-head='git-fixup HEAD' 30 | 31 | git-autosquash () { 32 | num_rex='^[0-9]+$' 33 | if [ -z "$1" ] || ! [[ "$1" =~ $num_rex ]] 34 | then 35 | echo "Please enter the number of commits from HEAD" 36 | echo "e.g.) gitAutosquash 2" 37 | echo "runs git rebase -i --autosquash HEAD~2" 38 | else 39 | git rebase -i --autosquash "HEAD~$1" 40 | fi 41 | } 42 | 43 | gitpullall() 44 | { 45 | repos_to_ignore="origin" 46 | should_ignore=-1 47 | 48 | echo "running: git pull" 49 | git pull 50 | echo "" 51 | 52 | for remote in `git remote` 53 | do 54 | echo "==================================" 55 | echo "Remote: $remote" 56 | echo "----------------------------------" 57 | for ignore in $repos_to_ignore 58 | do 59 | [ "$remote" = "$ignore" ] && { should_ignore=1; break; } || : 60 | done 61 | 62 | if [ "$should_ignore" = "-1" ] 63 | then 64 | THIS_BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` 65 | { git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME$" 2>&1 > /dev/null } || { git branch -r | grep -s "^[[:space:]]\+$remote/$THIS_BRANCH_NAME""[[:space:]]\+" 2>&1 > /dev/null } || { 66 | echo "No info of the remote repo named '$remote' is found." 67 | echo "So $remote will be fetched." 68 | echo "running: git fetch $remote" 69 | git fetch "$remote" 70 | echo "" 71 | } 72 | if git branch -r | grep -sw "$remote/$THIS_BRANCH_NAME" 2>&1 > /dev/null ; then 73 | echo "running: git pull $remote $THIS_BRANCH_NAME" 74 | git pull "$remote" "$THIS_BRANCH_NAME" 75 | else 76 | echo "$THIS_BRANCH_NAME branch does not exist on the remote called '$remote'." 77 | echo "So $remote will not be pulled from $remote." 78 | fi 79 | else 80 | echo "$remote is on the ignored list so ignore it." 81 | echo "Ignored: $remote" 82 | fi 83 | should_ignore=-1 84 | echo "==================================" 85 | echo "" 86 | done 87 | } 88 | 89 | 90 | git_fetch_upstream() { 91 | NC='\033[0m' 92 | LIGHT_BLUE='\033[1;34m' 93 | LIGHT_GREEN='\033[1;32m' 94 | RED="\033[0;31m" 95 | 96 | if git remote | grep -w upstream 2>&1 > /dev/null ; then 97 | if [ -n "$1" ] 98 | then 99 | printf "${LIGHT_BLUE}upstream info found: ${NC}\n" 100 | printf "${LIGHT_GREEN}running: git remote ${NC}\n" 101 | git remote 102 | branch_name="$1" 103 | printf "\n${LIGHT_GREEN}running: git fetch upstream ${NC}\n" 104 | git fetch upstream 105 | printf "\n${LIGHT_GREEN}running: git checkout $branch_name ${NC}\n" 106 | git checkout $branch_name 107 | printf "\n${LIGHT_GREEN}running: git merge upstream/$branch_name ${NC}\n" 108 | git merge "upstream/$branch_name" 109 | echo "" 110 | else 111 | printf "${RED}Please enter the branch name.${NC}\n" 112 | echo " git-fetch-upstream master " 113 | echo " git-fetch-upstream my-branch " 114 | echo "" 115 | fi 116 | else 117 | printf "${RED}upstream branch does not exist please add it first.${NC}\n" 118 | echo "" 119 | printf "git remote add upstream ${LIGHT_GREEN}GIT_REMOTE_REPOSITORY${NC}\n" 120 | echo "" 121 | echo "e.g.) " 122 | printf "git remote add upstream ${LIGHT_GREEN}git@github.com:SOME_USER/some-project.git${NC}\n" 123 | echo "" 124 | fi 125 | } 126 | 127 | git_find_file() { 128 | missing_data=0 129 | if [ -z "$1" ] 130 | then 131 | missing_data=1 132 | echo "Git repo locaiton is missing." 133 | fi 134 | if [ -z "$2" ] 135 | then 136 | missing_data=1 137 | echo "The filename of the file you're looking for is missing." 138 | fi 139 | if [ $missing_data != 0 ] 140 | then 141 | echo "usage)" 142 | echo "git_find_file GIT_REPO_LOCATION FILE_NAME BRANCH " 143 | echo "BRANCH is optional and when missing, master is used." 144 | echo "git_find_file ssh://git@github.com:username/project.git build.sbt develop " 145 | else 146 | if [ -z "$3" ] 147 | then 148 | echo "The branch is missing so it will use master." 149 | branch_name="master" 150 | else 151 | branch_name="$3" 152 | fi 153 | 154 | git archive --format=tar --remote="$1" $branch_name "$2" >/dev/null && echo "FOUND" || echo "NOT THERE"; 155 | fi 156 | 157 | } 158 | 159 | 160 | ## } Git 161 | -------------------------------------------------------------------------------- /dot-files/zsh/.my-shell-common: -------------------------------------------------------------------------------- 1 | if type exa >/dev/null 2>&1; then 2 | alias ls0='command ls -G' 3 | alias ll0='ls0 -l' 4 | alias l0='ls0 -al' 5 | alias ls='exa' 6 | else 7 | alias ls='ls -G' 8 | fi 9 | 10 | alias sudos='sudo -s' 11 | 12 | alias psaux='ps aux | grep -v grep | grep' 13 | 14 | alias du-mbs='{ du -sh .[^.]* * || du -sh * } | egrep -e "^[ 0-9]*[.]?[0-9]*[M]" | sort -n' 15 | alias du-gbs='{ du -sh .[^.]* * || du -sh * } | egrep -e "^[ 0-9]*[.]?[0-9]*[G]" | sort -n' 16 | 17 | alias sshnp='ssh -o PubkeyAuthentication=no' 18 | alias scpnp='scp -o PubkeyAuthentication=no' 19 | alias ssh-p='ssh -p' 20 | alias scp-p='scp -P' 21 | 22 | search_file() { 23 | if [ ! -n "$1" ] 24 | then 25 | echo "Please enter a word to search" 26 | exit 27 | fi 28 | 29 | while read -r file 30 | do 31 | grep -H "$1" "${file}" 32 | done <<< "$(find . -type f -exec grep -Iq . {} \; -and -print)" 33 | } 34 | -------------------------------------------------------------------------------- /other/gitignore_files/eclipse_java_spring/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | 3 | *.pydevproject 4 | .project 5 | .classpath 6 | /.settings/ 7 | */.settings/* 8 | !PROJECT_NAME/.settings/.jsdtscope 9 | .metadata 10 | bin/ 11 | 12 | ajcore.*.txt 13 | 14 | tmp/ 15 | *.tmp 16 | *.bak 17 | *.swp 18 | *~.nib 19 | local.properties 20 | .loadpath 21 | 22 | # External tool builders 23 | .externalToolBuilders/ 24 | 25 | # Locally stored "Eclipse launch configurations" 26 | *.launch 27 | 28 | # CDT-specific 29 | .cproject 30 | 31 | # PDT-specific 32 | .buildpath 33 | 34 | # for Mac 35 | .DS_Store -------------------------------------------------------------------------------- /other/gitignore_files/eclipse_scala_play/.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | project/project 3 | project/target 4 | target 5 | tmp 6 | .history 7 | dist 8 | /.idea 9 | /*.iml 10 | /out 11 | /.idea_modules 12 | /.classpath 13 | /.project 14 | /RUNNING_PID 15 | /.settings 16 | /bin 17 | /.target 18 | /.cache 19 | -------------------------------------------------------------------------------- /scripts/README-kr.md: -------------------------------------------------------------------------------- 1 | [English Version](README.md "English Version") 2 | 스크립트 3 | ======= 4 | 5 | ## 디스크 사용량 보기 6 | ```bash 7 | $ df -h 8 | ``` 9 | 10 | ## 디스크 공간 사용량 보기 11 | ```bash 12 | $ du -sh 13 | ``` 14 | 15 | * 1MB이상 되는 폴더와 파일 나열하기 16 | 17 | ```bash 18 | $ du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[M]" | sort -n 19 | ``` 20 | 21 | * 1GB이상 되는 폴더와 파일 나열하기 22 | 23 | ```bash 24 | $ du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[G]" | sort -n 25 | ``` 26 | 27 | ## 파일 사이즈로 파일 찾기 28 | * 1MiB보다 큰 ZIP 파일들 모두 찾기. 29 | 30 | ```bash 31 | $ find . -type f -size +1M -name "*.zip" -exec ls -lh {} \; | sort -k 5 -n 32 | ``` 33 | 34 | ## 원하는 단어가 포함된 파일 검색하기 35 | * 현재 위치에서 원하는 단어가 포함된 모든 파일 찾기. 36 | 37 | ```bash 38 | $ for file in `find . -type f`; do grep -H "원하는단어" $file; done 39 | ``` 40 | 41 | 42 | ## 내가 현재 사용중인 쉘 알아내기 43 | * 알아내는 방법이 여러가지. 44 | * `echo $0` 45 | 46 | ```bash 47 | $ echo $0 48 | ``` 49 | 50 | * `ps -p $$ ` or `ps --no-headers -p $$ | awk '{ print $4; }'`
51 | 52 | ```bash 53 | $ ps -p $$ 54 | 3732 pts/6 00:00:00 bash 55 | ``` 56 | ```bash 57 | $ ps --no-headers -p $$ | awk '{ print $4; }' 58 | ``` 59 | * `echo $SHELL` 60 | 61 | ```bash 62 | $ echo $SHELL 63 | /bin/bash 64 | ``` 65 | 66 | ## [ImageMagick](http://www.imagemagick.org/ "ImageMagick")을 이용한 이미지 크기변환 67 | * 현재 디렉토리에 있는 PNG 파일의 이미지 크기 모두 변환하기. 68 | 69 | ```bash 70 | # 크기: 300x150 (하지만 원본 이미지의 크기 비율을 유지한다.) 71 | $ for file in *.png; do convert $file -resize 300x150 thumbnail-$file; done 72 | ``` 73 | 74 | ```bash 75 | # 크기: 300x150 (원본 이미지의 크기 비율을 무시하고 76 | # 가로 300픽셀, 세로 150픽셀의 크기로 변환한다.) 77 | $ for file in *.png; do convert $file -resize 300x150 thumbnail-$file; done 78 | ``` 79 | 80 | ```bash 81 | # 가로 300픽셀의 이미지로 변환. 82 | $ for file in *.png; do convert $file -resize 300 thumbnail-$file; done 83 | ``` 84 | 85 | ```bash 86 | # 세로 150픽셀의 이미지로 변환 87 | $ for file in *.png; do convert $file -resize x150 thumbnail-$file; done 88 | ``` 89 | 90 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | [한국어 버전](README-kr.md "한국어 버전") 2 | Scripts 3 | ======= 4 | 5 | ## report file system disk space usage 6 | ```bash 7 | $ df -h 8 | ``` 9 | 10 | ## Estimate file space usage 11 | ```bash 12 | $ du -sh 13 | ``` 14 | 15 | * List all the folders and files which are equal to or greater than 1MB. 16 | 17 | ```bash 18 | $ du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[M]" | sort -n 19 | ``` 20 | 21 | * List all the folders and files which are equal to or greater than 1GB. 22 | 23 | ```bash 24 | $ du -sh .[^.]* * | egrep -e "^[ 0-9]*[.]?[0-9]*[G]" | sort -n 25 | ``` 26 | 27 | ## Find files by size 28 | * Find all zip files which are bigger than 1MiB. 29 | 30 | ```bash 31 | $ find . -type f -size +1M -name "*.zip" -exec ls -lh {} \; | sort -k 5 -n 32 | ``` 33 | 34 | ## Searching files containing word 35 | * In the current location, Searching all files which contain the given word. 36 | 37 | ```bash 38 | $ for file in `find . -type f`; do grep -H "WORD_HERE" $file; done 39 | ``` 40 | 41 | 42 | ## Find out What Shell I'm Using 43 | * There are several ways to find it out. 44 | * `echo $0` 45 | 46 | ```bash 47 | $ echo $0 48 | ``` 49 | 50 | * `ps -p $$ ` or `ps --no-headers -p $$ | awk '{ print $4; }'`
51 | 52 | ```bash 53 | $ ps -p $$ 54 | 3732 pts/6 00:00:00 bash 55 | ``` 56 | ```bash 57 | $ ps --no-headers -p $$ | awk '{ print $4; }' 58 | ``` 59 | * `echo $SHELL` 60 | 61 | ```bash 62 | $ echo $SHELL 63 | /bin/bash 64 | ``` 65 | 66 | ## Resizing Image using [ImageMagick](http://www.imagemagick.org/ "ImageMagick") 67 | * Resize all PNG files in the current directory. 68 | 69 | ```bash 70 | # size: 300x150 (But it will preserve the aspect ratio of the source image.) 71 | $ for file in *.png; do convert $file -resize 300x150 thumbnail-$file; done 72 | ``` 73 | 74 | ```bash 75 | # size: 300x150 (It will ignore the aspect ratio of the source image and 76 | # resize it 300 pixels in width and 150 pixels in height.) 77 | $ for file in *.png; do convert $file -resize 300x150 thumbnail-$file; done 78 | ``` 79 | 80 | ```bash 81 | # set width to 300 pixels 82 | $ for file in *.png; do convert $file -resize 300 thumbnail-$file; done 83 | ``` 84 | 85 | ```bash 86 | # set height to 150 pixels 87 | $ for file in *.png; do convert $file -resize x150 thumbnail-$file; done 88 | ``` 89 | 90 | -------------------------------------------------------------------------------- /scripts/String.md: -------------------------------------------------------------------------------- 1 | # Handle String 2 | 3 | ## Split 4 | * Separate String by `-` 5 | ```shell 6 | SOME_VAR="abc-123" 7 | SOME_PREFIX=(${SOME_VAR//-*/ }) 8 | 9 | echo $SOME_PREFIX 10 | 11 | # Result 12 | abc 13 | ``` 14 | 15 | ```shell 16 | SOME_VAR="abc-123" 17 | SOME_SUFFIX=(${SOME_VAR//*-/ }) 18 | 19 | echo $SOME_SUFFIX 20 | 21 | # Result 22 | 123 23 | ``` 24 | ## Trim 25 | ```shell 26 | SOME_VAR=" abc-123 " 27 | TRIMMED_VAR=(${SOME_VAR// }) 28 | 29 | echo "SOME_VAR='$SOME_VAR'" 30 | echo "TRIMMED_VAR='$TRIMMED_VAR'" 31 | 32 | # Result: 33 | SOME_VAR=' abc-123 ' 34 | TRIMMED_VAR='abc-123' 35 | ``` 36 | -------------------------------------------------------------------------------- /scripts/backup-mysql-db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ########################################################## 3 | ## Simple script to back up mysql databases. ## 4 | ## @author Lee, SeongHyun (Kevin) ## 5 | ## @veraion 0.0.1 (2012-05-02) ## 6 | ########################################################## 7 | current_date=$(date +"%Y-%m-%d") 8 | 9 | default_pwd=$PWD 10 | target_dir=$default_pwd 11 | if [ -n "$1" ] 12 | then 13 | target_dir=$1 14 | fi 15 | echo "The backup files will be created in $target_dir directory." 16 | echo 17 | 18 | cd $target_dir 19 | 20 | IGNORE_DBS="information_schema" 21 | 22 | DBS="information_schema mysql db_name1 db_name2" 23 | 24 | 25 | echo -n "Please enter password: " 26 | 27 | stty -echo 28 | read PASSWORD_FOR_DB 29 | stty echo 30 | 31 | for db in $DBS 32 | do 33 | skipdb=-1 34 | if [ "$IGNORE_DBS" != "" ]; 35 | then 36 | for i_db in $IGNORE_DBS 37 | do 38 | [ "$db" == "$i_db" ] && skipdb=1 || : 39 | done 40 | fi 41 | 42 | if [ "$skipdb" == "-1" ] ; then 43 | echo -e "\n" 44 | echo "Backing up $db..." 45 | echo "please wait..." 46 | mysqldump --opt -h localhost -u root -p$PASSWORD_FOR_DB $db > DB_BackUp_$db\_$current_date.sql 47 | echo "done" 48 | echo "Create checksum..." 49 | sha1sum DB_BackUp_$db\_$current_date.sql > DB_BackUp_$db\_$current_date.sql.sha1 50 | echo "done" 51 | fi 52 | done 53 | echo -e "\nCreate a tar.gz file..." 54 | tar -czvf DB_BackUp_All_DB_$current_date.tar.gz DB_BackUp_*_$current_date.sql* 55 | 56 | echo "" 57 | echo "All the specified databases have been backed up." 58 | exit 59 | -------------------------------------------------------------------------------- /scripts/ps-killer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################# 3 | ## Simple script to kill processes ## 4 | ## ## 5 | ## @author Lee, SeongHyun (Kevin) ## 6 | ## @veraion 0.0.1 (2013-02-19) ## 7 | ## ## 8 | ## http://lckymn.com ## 9 | ############################################# 10 | 11 | THIS_SCRIPT_NAME="$(basename $0)" 12 | 13 | LINES1="----------------------------------------------------------" 14 | LINES2="==========================================================" 15 | 16 | if [ -n "$1" ] 17 | then 18 | RESULT="`ps aux | egrep -vw 'egrep|'$0 | egrep $1 | awk '{ print $2"\t"substr($0, index($0, $11)); }'`" 19 | 20 | if [ -n "$RESULT" ] 21 | then 22 | echo -e "$LINES2\n### PROCESS LIST ###\n$LINES1" 23 | echo "$RESULT" 24 | echo $LINES2 25 | echo "Kill (all: a / one by one: o / cancel: c)" 26 | typeset -l ANSWER 27 | read ANSWER 28 | if [[ "$ANSWER" == "a" || "$ANSWER" == "all" ]] 29 | then 30 | kill -9 `echo -e "$RESULT" | awk '{ print $1; }'` 31 | echo "killing all of the following process(es) has been done." 32 | echo -e "$RESULT" 33 | elif [[ "$ANSWER" == "o" || "$ANSWER" == "one" ]] 34 | then 35 | TMP_IFS=$IFS 36 | IFS=$'\n' 37 | for EACH in $RESULT 38 | do 39 | echo -e "\n$LINES1\n$EACH" 40 | echo "Kill it? (yes: y/no: n)" 41 | read ANSWER 42 | if [[ "$ANSWER" == "y" || "$ANSWER" == "yes" ]] 43 | then 44 | kill -9 `echo -e "$EACH" | awk '{ print $1; }'` 45 | echo "Killing \"$EACH\": Done." 46 | else 47 | echo "Ignore killing \"$EACH\"" 48 | fi 49 | echo "$LINES1" 50 | done 51 | IFS=$TMP_IFS 52 | 53 | echo "There is no more process to be killed." 54 | else 55 | echo "$LINES2" 56 | echo "Killing the following process(es) has been cancelled." 57 | echo "$LINES1" 58 | echo -e "$RESULT" 59 | echo "$LINES1" 60 | fi 61 | else 62 | echo "No matching process with the given keyword ('$1') is found." 63 | fi 64 | else 65 | echo "Please enter a process name." 66 | echo "e.g.) to kill a flash player" 67 | echo "$THIS_SCRIPT_NAME flash" 68 | fi 69 | 70 | exit 71 | -------------------------------------------------------------------------------- /scripts/setup-scala.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################# 3 | ## Script ## 4 | ## to install / reinstall / remove Scala ## 5 | ## ## 6 | ## @author Lee, SeongHyun (Kevin) ## 7 | ## @veraion 0.0.1 (2013-06-11) ## 8 | ## ## 9 | ## http://lckymn.com ## 10 | ############################################# 11 | 12 | THIS_SCRIPT_NAME="$(basename $0)" 13 | 14 | if [ $EUID != 0 ] 15 | then 16 | echo "You must run this script with a super user privilege." 17 | echo -e "Try \n$ sudo $THIS_SCRIPT_NAME " 18 | exit 19 | fi 20 | 21 | LINES1="-------------------------------------------------------------------------------" 22 | LINES2="===============================================================================" 23 | 24 | USR_BIN="/usr/bin" 25 | 26 | USR_SHARE="/usr/share" 27 | USR_SHARE_SCALA="$USR_SHARE/scala" 28 | USR_SHARE_SCALA_BIN="$USR_SHARE_SCALA/bin" 29 | 30 | USR_SHARE_BIN_FSC="$USR_SHARE_SCALA_BIN/fsc" 31 | USR_BIN_FSC="$USR_BIN/fsc" 32 | 33 | USR_SHARE_BIN_SCALA="$USR_SHARE_SCALA_BIN/scala" 34 | USR_BIN_SCALA="$USR_BIN/scala" 35 | 36 | USR_SHARE_BIN_SCALAC="$USR_SHARE_SCALA_BIN/scalac" 37 | USR_BIN_SCALAC="$USR_BIN/scalac" 38 | 39 | USR_SHARE_BIN_SCALADOC="$USR_SHARE_SCALA_BIN/scaladoc" 40 | USR_BIN_SCALADOC="$USR_BIN/scaladoc" 41 | 42 | USR_SHARE_BIN_SCALAP="$USR_SHARE_SCALA_BIN/scalap" 43 | USR_BIN_SCALAP="$USR_BIN/scalap" 44 | 45 | typeset -l ANSWER 46 | 47 | take_answer() { 48 | read ANSWER 49 | while [[ "$ANSWER" != "yes" && "$ANSWER" != "no" && "$ANSWER" != "y" && "$ANSWER" != "n" ]] 50 | do 51 | echo "" 52 | echo "Please choose either 'yes' or 'no' ('y' or 'n') without quotes" 53 | echo -e "$1" 54 | echo "Would you like to proceed? (yes/no | y/n)" 55 | read ANSWER 56 | done 57 | } 58 | 59 | remove_scala() { 60 | echo "[WARNING!!!] Uninstalling Scala will remove the existing Scala " 61 | echo "from $USR_SHARE_SCALA and remove all the link to scala executable from $USR_BIN." 62 | echo "Would you like to uninstall scala? (y/n | yes/no)" 63 | take_answer "It will remove the existing Scala from $USR_SHARE_SCALA and remove all the links to scala executable from $USR_BIN." 64 | if [[ "$ANSWER" == "yes" || "$ANSWER" == "y" ]] 65 | then 66 | echo "$LINES1" 67 | echo "Remove existing scala directory ($USR_SHARE_SCALA)." 68 | if [[ ! -d "$USR_SHARE_SCALA" && ! -L "$USR_SHARE_SCALA" ]] 69 | then 70 | echo "$USR_SHARE_SCALA does not exist so skip it." 71 | else 72 | echo "rm -R $USR_SHARE_SCALA " 73 | rm -R $USR_SHARE_SCALA 74 | echo "Done." 75 | fi 76 | echo "$LINES1" 77 | echo "Remove existing scala executable links from $USR_BIN." 78 | if [[ ! -f "$USR_BIN_FSC" && ! -L "$USR_BIN_FSC" ]] 79 | then 80 | echo "$USR_BIN_FSC does not exist so skip it." 81 | else 82 | echo "rm $USR_BIN_FSC" 83 | rm "$USR_BIN_FSC" 84 | fi 85 | 86 | if [[ ! -f "$USR_BIN_SCALA" && ! -L "$USR_BIN_SCALA" ]] 87 | then 88 | echo "$USR_BIN_SCALA does not exist so skip it." 89 | else 90 | echo "rm $USR_BIN_SCALA" 91 | rm "$USR_BIN_SCALA" 92 | fi 93 | 94 | if [[ ! -f "$USR_BIN_SCALAC" && ! -L "$USR_BIN_SCALAC" ]] 95 | then 96 | echo "$USR_BIN_SCALAC does not exist so skip it." 97 | else 98 | echo "rm $USR_BIN_SCALAC" 99 | rm "$USR_BIN_SCALAC" 100 | fi 101 | 102 | if [[ ! -f "$USR_BIN_SCALADOC" && ! -L "$USR_BIN_SCALADOC" ]] 103 | then 104 | echo "$USR_BIN_SCALADOC does not exist so skip it." 105 | else 106 | echo "rm $USR_BIN_SCALADOC" 107 | rm "$USR_BIN_SCALADOC" 108 | fi 109 | 110 | if [[ ! -f "$USR_BIN_SCALAP" && ! -L "$USR_BIN_SCALAP" ]] 111 | then 112 | echo "$USR_BIN_SCALAP does not exist so skip it." 113 | else 114 | echo "rm $USR_BIN_SCALAP" 115 | rm "$USR_BIN_SCALAP" 116 | fi 117 | echo "Done." 118 | echo "$LINES1" 119 | else 120 | echo "$LINES1" 121 | echo "Uninstalling Scala has been cancelled. Bye~!" 122 | echo "$LINES1" 123 | exit 124 | fi 125 | } 126 | 127 | NEW_SCALA_PATH="" 128 | 129 | get_new_scala_path() { 130 | if [ -n "$1" ] 131 | then 132 | NEW_SCALA_PATH="$1" 133 | 134 | if [[ "$NEW_SCALA_PATH" != /* ]] 135 | then 136 | NEW_SCALA_PATH="`pwd`/$NEW_SCALA_PATH" 137 | fi 138 | else 139 | NEW_SCALA_PATH="" 140 | fi 141 | } 142 | 143 | assert_dir_or_link_exists() { 144 | if [[ ! -d "$1" && ! -L "$1" ]] 145 | then 146 | DIR="$2 directory" 147 | if [ ! -n "$2" ] 148 | then 149 | DIR="directory" 150 | fi 151 | echo "The $DIR, $1, does not exist." 152 | exit 1 153 | fi 154 | } 155 | 156 | install_scala() { 157 | if [ -n "$1" ] 158 | then 159 | get_new_scala_path "$1" 160 | echo "$LINES2" 161 | 162 | assert_dir_or_link_exists "$NEW_SCALA_PATH" "scala" 163 | 164 | if [[ -d "$USR_SHARE_SCALA" || -L "$USR_SHARE_SCALA" ]] 165 | then 166 | echo "$USR_SHARE_SCALA already exists." 167 | echo "Please remove the existing one first " 168 | echo "or run reinstall instead of install" 169 | echo "e.g.) $THIS_SCRIPT_NAME reinstall SCALA_DIR" 170 | echo "$LINES1" 171 | echo "Installing $NEW_SCALA_PATH has been cancelled. Bye~!" 172 | echo "$LINES1" 173 | exit 174 | fi 175 | 176 | echo "Installing Scala: It will copy " 177 | echo "$NEW_SCALA_PATH" 178 | echo " to " 179 | echo "$USR_SHARE_SCALA" 180 | echo "Would you like to proceed? (y/n | yes/no)" 181 | take_answer "Installing Scala: It will copy \n$NEW_SCALA_PATH\n to \n$USR_SHARE_SCALA" 182 | 183 | if [[ "$ANSWER" == "no" || "$ANSWER" == "n" ]] 184 | then 185 | echo "$LINES1" 186 | echo "Installing $NEW_SCALA_PATH has been cancelled. Bye~!" 187 | echo "$LINES1" 188 | exit 189 | fi 190 | 191 | # install 192 | echo "$LINES1" 193 | echo "Copying $NEW_SCALA_PATH -> $USR_SHARE_SCALA" 194 | echo "cp -R $NEW_SCALA_PATH $USR_SHARE_SCALA " 195 | cp -R "$NEW_SCALA_PATH" "$USR_SHARE_SCALA" 196 | echo "Done." 197 | echo "$LINES1" 198 | 199 | echo "Creating symbolic link of scala executable files in bin dir if it doesn't exist." 200 | echo "$LINES1" 201 | if [[ -f "$USR_BIN_FSC" || -L "$USR_BIN_FSC" ]] 202 | then 203 | echo "$USR_BIN_FSC exists so skip it." 204 | else 205 | echo "ln -s $USR_SHARE_BIN_FSC" "$USR_BIN_FSC " 206 | ln -s "$USR_SHARE_BIN_FSC" "$USR_BIN_FSC" 207 | fi 208 | 209 | if [[ -f "$USR_BIN_SCALA" || -L "$USR_BIN_SCALA" ]] 210 | then 211 | echo "$USR_BIN_SCALA exists so skip it." 212 | else 213 | echo "ln -s $USR_SHARE_BIN_SCALA" "$USR_BIN_SCALA" 214 | ln -s "$USR_SHARE_BIN_SCALA" "$USR_BIN_SCALA" 215 | fi 216 | 217 | if [[ -f "$USR_BIN_SCALAC" || -L "$USR_BIN_SCALAC" ]] 218 | then 219 | echo "$USR_BIN_SCALAC exists so skip it." 220 | else 221 | echo "ln -s $USR_SHARE_BIN_SCALAC" "$USR_BIN_SCALAC " 222 | ln -s "$USR_SHARE_BIN_SCALAC" "$USR_BIN_SCALAC" 223 | fi 224 | 225 | if [[ -f "$USR_BIN_SCALADOC" || -L "$USR_BIN_SCALADOC" ]] 226 | then 227 | echo "$USR_BIN_SCALADOC exists so skip it." 228 | else 229 | echo "ln -s $USR_SHARE_BIN_SCALADOC" "$USR_BIN_SCALADOC " 230 | ln -s "$USR_SHARE_BIN_SCALADOC" "$USR_BIN_SCALADOC" 231 | fi 232 | 233 | if [[ -f "$USR_BIN_SCALAP" || -L "$USR_BIN_SCALAP" ]] 234 | then 235 | echo "$USR_BIN_SCALAP exists so skip it." 236 | else 237 | echo "ln -s $USR_SHARE_BIN_SCALAP" "$USR_BIN_SCALAP " 238 | ln -s "$USR_SHARE_BIN_SCALAP" "$USR_BIN_SCALAP" 239 | fi 240 | echo "Done." 241 | echo "$LINES1" 242 | echo "You probably want to add \$SCALA_HOME to ~/.bashrc " 243 | echo "e.g.)" 244 | echo "export SCALA_HOME=$USR_SHARE_SCALA" 245 | echo "$LINES2" 246 | else 247 | echo "Please enter the scala directory name." 248 | echo "e.g.)" 249 | echo "$ $THIS_SCRIPT_NAME install scala-2.10.2 " 250 | exit 1 251 | fi 252 | } 253 | 254 | 255 | reinstall_scala() { 256 | if [ -n "$1" ] 257 | then 258 | get_new_scala_path "$1" 259 | echo "$LINES2" 260 | 261 | assert_dir_or_link_exists "$NEW_SCALA_PATH" "scala" 262 | 263 | if [[ -d "$USR_SHARE_SCALA" || -L "$USR_SHARE_SCALA" ]] 264 | then 265 | echo "$USR_SHARE_SCALA already exists." 266 | echo "Would you like to remove it (including executable links in $USR_BIN) " 267 | echo "and install the new one? (y/n | yes/no)" 268 | 269 | take_answer "It will remove the existing '$USR_SHARE_SCALA' directory and install '$NEW_SCALA_PATH'." 270 | 271 | if [[ "$ANSWER" == "yes" || "$ANSWER" == "y" ]] 272 | then 273 | echo "$LINES1" 274 | remove_scala 275 | echo "$LINES1" 276 | else 277 | echo "$LINES1" 278 | echo "Reinstalling $NEW_SCALA_PATH has been cancelled. Bye~!" 279 | echo "$LINES1" 280 | exit 281 | fi 282 | else 283 | echo "$LINES1" 284 | echo "$USR_SHARE_SCALA does not exist so skip uninstallation." 285 | echo "$LINES1" 286 | fi 287 | install_scala "$1" 288 | else 289 | echo "Please enter the scala directory name." 290 | echo "e.g.)" 291 | echo "$ $THIS_SCRIPT_NAME reinstall scala-2.10.2 " 292 | exit 1 293 | fi 294 | } 295 | 296 | case $1 in 297 | reinstall) 298 | reinstall_scala "$2" 299 | ;; 300 | install) 301 | install_scala "$2" 302 | ;; 303 | remove) 304 | remove_scala 305 | ;; 306 | *) 307 | echo "[ERROR] Unknown option: $1" 308 | echo "* Usage: " 309 | echo " * Installation: " 310 | echo " $THIS_SCRIPT_NAME install NEW_SCALA_DIR " 311 | echo "" 312 | echo " * Reinstallation: " 313 | echo " $THIS_SCRIPT_NAME reinstall NEW_SCALA_DIR " 314 | echo "" 315 | echo " * Uninstallation: " 316 | echo " $THIS_SCRIPT_NAME remove " 317 | ;; 318 | esac 319 | exit 320 | -------------------------------------------------------------------------------- /scripts/tomcat-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################### 3 | ## Script to start / stop / restart Tomcat ## 4 | ## ## 5 | ## @author Lee, SeongHyun (Kevin) ## 6 | ## @veraion 0.0.1 (2013-05-16) ## 7 | ## ## 8 | ## http://lckymn.com ## 9 | ############################################### 10 | 11 | THIS_SCRIPT_NAME="$(basename $0)" 12 | 13 | TOMCAT_HOME="/path/to/tomcat" 14 | 15 | TOMCAT_SH="/etc/init.d/tomcat" 16 | 17 | # If you have more than one Tomcat instance running, you probably want to use another keyword such as the home or bin directory of each Tomcat. 18 | TOMCAT_PROCESS_KEYWORD="org.apache.catalina.startup.Bootstrap" 19 | # TOMCAT_PROCESS_KEYWORD="$TOMCAT_HOME/bin/" 20 | 21 | 22 | if [ ! -f "$TOMCAT_SH" ] 23 | then 24 | echo -e "[ERROR] Tomcat start/stop script ('$TOMCAT_SH') does not exist!\n" 25 | exit 26 | fi 27 | 28 | if [ ! -n "$1" ] 29 | then 30 | echo "[ERROR] No option is given." 31 | echo "* Available options are:" 32 | echo "start" 33 | echo "stop" 34 | echo "restart" 35 | echo "" 36 | echo "e.g.)" 37 | echo "$THIS_SCRIPT_NAME start " 38 | echo "$THIS_SCRIPT_NAME stop " 39 | echo "$THIS_SCRIPT_NAME restart " 40 | exit 41 | fi 42 | 43 | RESULT="" 44 | checkProcess() { 45 | RESULT="`ps aux | egrep -vw 'egrep|'$0 | egrep $TOMCAT_PROCESS_KEYWORD`" 46 | return 0 47 | } 48 | 49 | stop() { 50 | checkProcess 51 | 52 | if [ -n "$RESULT" ] 53 | then 54 | $TOMCAT_SH stop 55 | 56 | echo -e "\nStopping Tomcat..." 57 | 58 | checkProcess 59 | RESULT=`echo $RESULT` 60 | while [ -n "$RESULT" ] 61 | do 62 | sleep 1 63 | checkProcess 64 | RESULT=`echo $RESULT` 65 | done 66 | 67 | echo -e "Tomcat has been stopped." 68 | else 69 | echo "Tomcat is not running. So skip stop process." 70 | fi 71 | } 72 | 73 | start() { 74 | 75 | checkProcess 76 | 77 | if [ -n "$RESULT" ] 78 | then 79 | echo "Tomcat is already running. So skip start process." 80 | else 81 | $TOMCAT_SH start 82 | echo -e "\nStarting Tomcat..." 83 | echo "Done! check the Tomcat log to see if it has started properly." 84 | fi 85 | } 86 | 87 | restart() { 88 | START_TIME="`date +%s`" 89 | 90 | stop 91 | echo -e "Now start Tomcat again!\n" 92 | start 93 | 94 | END_TIME="`date +%s`" 95 | 96 | echo -e "It took $(($END_TIME - $START_TIME)) seconds.\n" 97 | echo -e "Restarting has been successfully done. Bye~!\n" 98 | } 99 | 100 | 101 | case $1 in 102 | restart) 103 | restart 104 | ;; 105 | stop) 106 | stop 107 | ;; 108 | start) 109 | start 110 | ;; 111 | *) 112 | echo "[ERROR] Unknown option: $1" 113 | ;; 114 | esac 115 | exit 116 | -------------------------------------------------------------------------------- /scripts/zsh/iterm2-how-to-use-ligatures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevin-lee/for-linux/f6d94a862256f0187c26405f36099a97459d2346/scripts/zsh/iterm2-how-to-use-ligatures.png -------------------------------------------------------------------------------- /scripts/zsh/osx-terminal-change-font-to-powerline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevin-lee/for-linux/f6d94a862256f0187c26405f36099a97459d2346/scripts/zsh/osx-terminal-change-font-to-powerline.png -------------------------------------------------------------------------------- /scripts/zsh/zsh-installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | ## For Ubuntu Linux 4 | ```shell 5 | sudo apt-get update && sudo apt-get install zsh 6 | ``` 7 | 8 | Install oh-my-zsh from https://github.com/ohmyzsh/ohmyzsh 9 | 10 | * Using curl 11 | 12 | ```shell 13 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 14 | ``` 15 | OR 16 | 17 | * Using wget 18 | 19 | ```shell 20 | sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 21 | ``` 22 | 23 | Change the default shell to z-shell 24 | 25 | ```shell 26 | chsh -s /bin/zsh 27 | ``` 28 | 29 | ## For Mac OSX 30 | 31 | ```shell 32 | brew update 33 | brew install zsh 34 | ``` 35 | 36 | Install oh-my-zsh from https://github.com/ohmyzsh/ohmyzsh 37 | 38 | * Using curl 39 | 40 | ```shell 41 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 42 | ``` 43 | OR 44 | 45 | * Using wget 46 | 47 | ```shell 48 | sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 49 | ``` 50 | 51 | Change the default shell to z-shell 52 | 53 | ```shell 54 | # You don't need it for the new macOS 55 | chsh -s /usr/local/bin/zsh 56 | ``` 57 | 58 | 59 | ## Install Powerline Fonts for `agnoster` theme 60 | **It is not necessary for Server** 61 | 62 | ```shell 63 | cd to/wherever/you/like 64 | git clone https://github.com/powerline/fonts powerline-fonts 65 | cd powerline-fonts 66 | ./install.sh 67 | ``` 68 | 69 | * Open `~/.zshrc` and change (**Do only this on Server**) 70 | 71 | ```shell 72 | ZSH_THEME="robbyrussell" 73 | ``` 74 | to 75 | 76 | ```shell 77 | ZSH_THEME="agnoster" 78 | ``` 79 | 80 | * Now, you need to change the terminal font to one of powerline ones. 81 | 82 | e.g.) Mac OS X 83 | 84 | ![Mac OS X Terminal: Use Powerline Font](osx-terminal-change-font-to-powerline.png) 85 | 86 | ## FiraCode 87 | I also recommend [FiraCode](https://github.com/tonsky/FiraCode) font, which supports ligatures. Both macOS's Terminal and iTerm2 support ligatures. 88 | 89 | In iTerm2, Open `Preferences` (Cmd+,) 90 | 1. `Profiles` tab 91 | 2. Select the profile you're using (or just the default one with `*`) 92 | 3. Move to the `Text` tab 93 | 4. Check the `Use ligatures` option 94 | 95 | ![iTerm2 settings to use ligatures](iterm2-how-to-use-ligatures.png) 96 | 97 | 98 | ## Install `zsh-syntax-highlighting` plugin 99 | 100 | ```shell 101 | cd ~/.oh-my-zsh/custom/plugins 102 | git clone git://github.com/zsh-users/zsh-syntax-highlighting.git 103 | ``` 104 | 105 | * Open `~/.zshrc` and change 106 | 107 | ```shell 108 | plugins=(git) 109 | ``` 110 | to 111 | 112 | ```shell 113 | plugins=(git zsh-syntax-highlighting) 114 | ``` 115 | -------------------------------------------------------------------------------- /tmux/README.md: -------------------------------------------------------------------------------- 1 | tmux 2 | ==== 3 | 4 | * Reattach an existing session 5 | 6 | ```shell 7 | tmux attach 8 | ``` 9 | 10 | * Detach from tmux (everything running will be in background) 11 | ``` 12 | ctrl+B, D 13 | ``` 14 | 15 | * New tmux session 16 | ``` 17 | ctrl+B, C 18 | ``` 19 | 20 | * Switch session 21 | ``` 22 | ctrl+B, 0~9 23 | ``` 24 | 25 | * Select a session from the list (Use the left and right arrow keys to see the list) 26 | ```shell 27 | ctrl+B, s 28 | ``` 29 | 30 | * Terminate the session 31 | ``` 32 | ctrl+D 33 | ``` 34 | 35 | * scroll (Use the up and down arrow keys) 36 | ``` 37 | ctrl + b + [ 38 | ``` 39 | --------------------------------------------------------------------------------