ditto

    ditto -V ~/Desktop/Test ~/Downloads/Test

get local Network info

get local hostname & ip address
    try {
        // 内网ip
        String ip = InetAddress.getLocalHost().getHostAddress();
        // hostname
        String hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        logger.error(e.getMessage(), e);
    }

Makefileユースケース


# リスト内のデータのみ許可する

TASK_LIST := migrate seed

.PHONY: %-test
%-test:
	$(if $(filter $(subst -test,,$@), $(TASK_LIST)),$(eval export TASK_NAME=$(subst -test,,$@)),$(error "Task name '$(subst -test,,$@)' is not defined."))
	echo $$TASK_NAME

ドロップダウンメニュー(CSSのみ)

(参考サイト) https://theorthodoxworks.com/web-design/drop-down-menu-multi-css/
<ul class="menu">
  <li class="menu_single"><a href="#" class="init-bottom">hoge</a>
    <ul class="menu_second_level">
      <li><a href="#">Child Menu</a></li>
      <li><a href="#">Child Menu</a></li>
      <li><a href="#">Child Menu</a></li>
    </ul>
  </li>
</ul>

test

Saved from https://stackoverflow.com/questions/54760478/why-does-python-copy-numpy-arrays-where-the-length-of-the-dimensions-are-the-sam
a = [np.array([0.0, 0.2, 0.4, 0.6, 0.8]),
     np.array([0.0, 0.2, 0.4, 0.6, 0.8]),
     np.array([0.0, 0.2, 0.4, 0.6])]

make

## 用法

```
make -f <dir>/Makefile <param>=<value>
```

Merging vs Rebasimg

In general, for local stuff, rebase is to be preferred. It leaves a nicer git history. 

### Merge
git checkout branch_you_want_to_merge_changes_into   
git merge branch_whose_changes_you_want

### Rebase
git checkout branch_whose_changes_you_want    
git rebase branch_you_want_to_rebase_changes_into

editorconfig file

Configuration - .editorconfig
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{ts,js,php}]
charset = utf-8

# 4 space indentation
[*.php]
indent_style = tab
indent_size = 4

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

Custom Hooks

Optional Arguments in Where Clause

SELECT NAME  
FROM TABLE  
WHERE  
    (@City IS NULL OR City = @City)
AND 
    (@Gender IS NULL OR Gender = @Gender)
AND 
    (@Age IS NULL OR Age = @Age) 

953. Verifying an Alien Dictionary

the order of the alphabet given words are sorted lexicographicaly
class Solution {
    int[] mapping = new int[26];
    public boolean isAlienSorted(String[] words, String order) {
        if(words.length <= 1)   return true;
        for(int i = 0; i < order.length(); i++)
            mapping[order.charAt(i) - 'a'] = i;
        for(int i = 0; i < words.length - 1; i++){
            if(compare(words[i], words[i + 1]) > 0)
                return false;
        }
        return true;
    }
    
    public int compare(String s1, String s2) {
        int cmp = 0;
        for(int i = 0, j = 0; i < s1.length() && j < s2.length() && cmp == 0; i++, j++)
            cmp = mapping[s1.charAt(i) - 'a'] - mapping[s2.charAt(j) - 'a'];    
        return cmp == 0 ? s1.length() - s2.length() : cmp;
    }
}

Import Data To Table

LOAD DATA LOCAL INFILE  'c:/tmp/discounts.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

Create and Copy Data from Existing Table(s)

CREATE TABLE table2 LIKE table1;
INSERT INTO table2 SELECT * FROM table1

680. Valid Palindrome II

// for (int k = i; k <= i + (j - i) / 2; k++) 等号

class Solution {
    public boolean validPalindrome(String s) {
        for (int i = 0; i < s.length() / 2; i++) {
            int j = s.length() - 1 - i;
            if (s.charAt(i) != s.charAt(j)) {
                return isPalindromeRange(s, i, j - 1) || isPalindromeRange(s, i + 1, j);
            }
        }
        return true;
    }
    
    private boolean isPalindromeRange(String s, int i, int j) {
        for (int k = i; k <= i + (j - i) / 2; k++) {
            if(s.charAt(k) != s.charAt(j - k + i)) {
                return false;
            }
        }
        return true;
    } 
}

1249. Minimum Remove to Make Valid Parentheses

left Parenthesis
// time/space complexity: O(n)

class Solution {
    public String minRemoveToMakeValid(String s) {
        Set<Integer> indexesToRemove = new HashSet<>();
        Stack<Integer> stack = new Stack<>();
        String res = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                stack.push(i);
            } else if (s.charAt(i) == ')') {
                if (stack.isEmpty()) {
                    indexesToRemove.add(i);
                } else {
                    stack.pop();
                }
            }
        }
        while (!stack.isEmpty()) {
            indexesToRemove.add(stack.pop());
        }
        for (int i = 0; i < s.length(); i++) {
            if (!indexesToRemove.contains(i)) {
                res += s.charAt(i);
            }
        }
        return res;
    }
}

widget custom as library

function randomNumber() {
  return Math.floor((Math.random() * 1000) + 1);
}

var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", "/c/custom/dashboard/widget_wc.js?" + randomNumber());
document.getElementsByTagName("head")[0].appendChild(script);

setTimeout(function(){  renderWidget(bodyContId); }, 1000);