Skip to content

Instantly share code, notes, and snippets.

View suewonjp's full-sized avatar

Suewon Bahng suewonjp

View GitHub Profile
@suewonjp
suewonjp / prefix_suffix.js
Created June 7, 2016 08:04
[JavaScript snippet] string prefix, suffix
function prefix(str, sep) {
// prefix("foo.bar.txt", ".") => foo
return str && str.substring(0, str.indexOf(sep));
}
function suffix(str, sep, excludeSep) {
// suffix("foo.bar.txt", ".") => .txt
// suffix("foo.bar.txt", ".", true) => txt
return str && str.substring(str.lastIndexOf(sep) + (excludeSep === true ? sep.length : 0));
}
@suewonjp
suewonjp / rmrf.sh
Last active June 7, 2016 08:32
[Bash tip] Safer 'rm -rf' command
#!/bin/sh
scriptName=${0##*/}
if [ $# = 0 ] ; then
echo "Wrapper script for the dangerous 'rm -rf'"
echo "Usage : $scriptName [folder to delete]"
exit 0
fi
@suewonjp
suewonjp / Open_iTerm2.txt
Last active July 28, 2016 13:45
[Mac OS X Tip] Open a new iTerm tab from the current folder in Finder
on run {input, parameters}
tell application "Finder"
set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
tell application "iTerm"
activate
@suewonjp
suewonjp / colorful-echo.sh
Last active January 6, 2017 11:29
Bash - Simple echo function to print colorful text
### Font colors
red=1 green=2 yellow=3 blue=4 magenta=5 cyan=6
### Font attributes
bold=1 underline=4 reverse=7
preecholor() {
printf '\e[%s;3%dm' "$1" "$2"
}
@suewonjp
suewonjp / check-version.sh
Last active January 7, 2017 09:28
compare two version notation strings in Bash
#!/bin/bash
versionAccepted() {
### $1 is the minimum required version, $2 is the version in question;
### If $1 < $2, return 0 (the input version is accepted)
### otherwise, return 1 (not accepted)
versions=( "$1" "$2" )
#printf "${versions[*]}\n"
for (( i=0; i<${#versions[@]}; ++i )); do
@suewonjp
suewonjp / Properly using Primefaces p:poll saving network traffic.java
Last active January 17, 2017 10:17
Properly using Primefaces p:poll saving network traffic
package com.civilizer.web.controller;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.civilizer.web.view.*;
@ManagedBean
@ViewScoped
public final class PollController {
@suewonjp
suewonjp / Building Primefaces from source.md
Last active January 18, 2017 10:31
Building Primefaces from source

https://github.com/primefaces/primefaces/wiki/Building-From-Source

  1. git-clone the packages:

     git clone https://github.com/primefaces/maven-jsf-plugin.git
     git clone https://github.com/primefaces/primefaces.git
    
  2. Find out maven-jsf-plugin version before trying to build Primefaces

  • Especially when you want to build older snapshots of Primefaces, you need to build maven-jsf-plugin that matches them
#!/bin/bash
sort_array() {
if [ -n "$1" ]; then
local IFS=$'\n'
eval "local arr=( \${$1[*]} )"
#arr=( $( printf "%s\n" ${arr[@]} | sort ) )
arr=( $( sort <<<"${arr[*]}" ) ) ### <<< is here string notation
eval "$1=( \${arr[*]} )"
fi
#!/usr/bin/env bash
## Preconditions;
## 1: Destination (Github) repository name == Source (local) repository name
## 2: [IMPORTANT!!!] Those two repositories (for GitHub & local) should be created prior to running this script
scriptName=${0##*/}
if [ $# -lt 1 ] ; then
echo "Usage : $scriptName [repo name] [github user name] [remote alias]"
@suewonjp
suewonjp / backup-functions.sh
Last active May 22, 2017 06:14
Bash Functions for Simple Directory Backup
checkBackupTarget() {
[ ! "$1" ] \
&& echo "Usage: $FUNCNAME [ directory-to-backup ]" \
&& echo "Note: the path should be relative" \
&& return 2
local tgtPath=$1
[ ! -d "$tgtPath" ] \
&& printf "$FUNCNAME : \"%s\" does NOT exist!!!\n" "$tgtPath" \