try_hugo, file as post

hello, org-mode in hugo #

Name Desc
org-mode markdown-like
hugo Jekyll-like

DONE image #

/ox-hugo/screenshot_2018-05-18_11-23-32.png

code #

cpp #

class Solution {
public:
    int coinChange(vector<int>& coins, int amount) {
        int res = INT_MAX;
        sort(coins.begin(), coins.end());
        vector<unordered_map<int, int>> record(coins.size());
        dfs(record, res, coins, amount, coins.size() - 1, 0);
        return res == INT_MAX? -1: res;
    }
    void dfs(vector<unordered_map<int, int>> &record, int& res,
             vector<int>& coins, int target, int idx, int count) {
        // cout << "idx:" << idx << "  target:" << target
        //      << " count" << count << endl;
        if (idx < 0) return;
        if(record[idx].count(target) > 0 and record[idx][target] <= count){
            // cout << "cached" << endl;
            return;
        }
        // if(record[idx].count(target) > 0 and record[idx][target] > count){
        //     cout << "cached, bigger: idx:" << idx
        //          << " target:" << target
        //          << " count:" << count
        //          << " cached count:" << record[idx][target] << endl;
        // }
        record[idx][target] = count;


        if (target % coins[idx] == 0) {
            res = min(res, count + target / coins[idx]);
            // record[idx][target] = count;  // this makes it wrong

            return;
        }
        for (int i = target / coins[idx]; i >= 0; i--) {
            if (count + i >= res - 1) break; // pruing
            dfs(record, res, coins, target - i * coins[idx], idx - 1, count + i);
        }
    }
};

python #

import sys


class HostPathMap:
    customization = {
    }

    def __getitem__(self, key):
        assert key.isdigit()
        return self.customization.get(
            key, ["192.168.1.{}".format(key)]
        )


name = sys.stdin.read().strip()
host, path = name.split("___")
path = path.replace("__", "/")
expanded_host, working_dir = HostPathMap()[host]
path = working_dir + path
command = """ssh {host} \"mkdir -p $(dirname {path})\";
scp ./{name} {host}:{path}""".format(
    name=name, host=expanded_host, path=path
)
sys.stdout.write(command)

shell #

#!/usr/bin/env bash

# Usage: callgrind.sh ls -la

set -e

wait_before_valgrind=1

echo "############################################################"
echo "  Will run:"
echo "  valgrind --tool=callgrind" "$@"
echo "  in $wait_before_valgrind second(s)."
echo "############################################################"

sleep $wait_before_valgrind

# use `head` will stop the stdout early. Use `tail` instead
pid=$(valgrind --tool=callgrind "$@" 2>&1 | \
          tee /dev/tty | \
          tail -n 1 | \
          grep -P -o '^==\d+==' | \
          grep -P -o '\d+')

wait_before_kcachegrind=2

echo "############################################################"
echo "  Valgrind finished. Pid: $pid"
echo "  Run \"kcachegrind callgrind.out.$pid\" in $wait_before_kcachegrind second(s)."
echo "############################################################"

sleep $wait_before_kcachegrind
# don't want to see output from kcachegrind, just want the gui.
kcachegrind "callgrind.out.$pid" >/dev/null 2>/dev/null

new headline #

New text.