selfjungle Just another WordPress weblog

21Apr/150

openwrt post-flash

# set root password
telnet 192.168.1.1
  passwd

# install web UI
ssh root@192.168.1.1
  opkg update
# if you'll get 404 errors, edit /etc/opkg.conf and change the package paths:
# https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/packages/packages
  opkg install luci-ssl
# if you have default_postinst: not found, script returned status 127 errors, check if the package version is ok: http://downloads.openwrt.org/barrier_breaker/14.07-rc3/ar71xx/generic/packages maybe?
# remove & try again:
opkg remove --force-remove luci-ssl px5g libustream-polarssl libpolarssl luci luci-proto-ppp luci-mod-admin-full luci-base luci-lib-nixio  uhttpd-mod-ubus  uhttpd lua luci-app-firewall  luci-theme-bootstrap libiwinfo-lua liblua libuci-lua rpcd luci-lib-ip libubus-lua

# start web server
/etc/init.d/uhttpd start
/etc/init.d/uhttpd enable

# enable wifi
uci set wireless.@wifi-device[0].disabled=0; uci commit wireless; wifi
uci show wireless | grep disabled

login to https://192.168.1.1 and do the rest...

Tagged as: No Comments
20Apr/150

zfs and portage’s var directories

While /var is usually for non-crucial content, caches, pid files, etc, portage has a different idea [1]:

/var/db/pkg Portage stores the state of your system
/var/lib/portage The versions for the applications you have explicitly installed

These directories store the current tree state, there is no way recreating them if they are deleted.

So if you plan to use ZFS with separate / and /var to take a snapshot of /, install some packages and then rollback the snapshot as you changed your mind, your / and /var will be out of sync!

/var/db/pkg and /var/lib/portage has to be on /.

cp -r /var/lib/portage /usr/portage/var_lib_portage
cp -r /var/db/pkg /usr/portage/var_db_pkg
rm -rf /var/lib/portage /var/db/pkg
ln -s /usr/portage/var_lib_portage /var/lib/portage
ln -s /usr/portage/var_db_pkg /var/db/pkg

[1] https://wiki.gentoo.org/wiki/Directories

Tagged as: , No Comments
20Apr/150

zfs set ditto blocks after file system creation

"The copies property works for all new writes, so I recommend that you set that policy when you create the file system or immediately after you create a zpool." [1]

So how can you force a complete reread-rewrite?
With (non-incremental) backup and restore:

# settings properties won't work:
zfs set copies=2 POOL/FS
zfs snapshot SNAPSHOT
zfs send SNAPSHOT | xz --threads=12 --verbose > FILE.img.xz
zfs destoy POOL/FS
xz --threads=12 --decompress --verbose  FILE.img.xz -c | zfs receive POOL/FS

# so you have to create & override a new FS with copies=2
zfs snapshot SNAPSHOT
zfs send SNAPSHOT | xz --threads=12 --verbose > FILE.img.xz
zfs destoy POOL/FS
zfs create ... -o copies=2  POOL/FS
xz --threads=12 --decompress --verbose  FILE.img.xz -c | zfs receive POOL/FS -F

[1] https://blogs.oracle.com/relling/entry/zfs_copies_and_data_protection

Tagged as: No Comments
30Mar/150

HiDPI

add -dpi 276 to /etc/X11/xinit/xserverrc

at firefox about:config set layout.css.devPixelsPerPx to 2

to be continued...

https://wiki.archlinux.org/index.php/HiDPI

Filed under: Uncategorized No Comments
27Mar/150

c++ for_each on multiple ranges

‚Ä©template<typename InputIter1, typename InputIter2, typename BinaryFunction>
BinaryFunction for_each_on_two_ranges(InputIter1 first1, InputIter1 last1, InputIter2 first2, BinaryFunction f) {
  for (; first1 != last1; ++first1, ++first2) {
    f(*first1, *first2);
  }
  return f;
}

or with variadic templates:

void increment_iterator() {}
template<typename Arg1, typename... Args>
void increment_iterator(Arg1& arg1, Args&... args)
{
  ++arg1;
  increment_iterator(args...);
}

template<typename InputIter1, typename Function, typename... InputIters>
Function for_each_N(InputIter1 first1, InputIter1 last1, Function f, InputIters... iters) {
  for (; first1 != last1; ++first1) {
    f(*first1, *iters...);
    increment_iterator(iters...);
  }
  return f;
}

the following functor can take any parameter:

template<typename T>
struct Add {
  Add() : value() {}

  void operator()() {}
  template<typename U=T, typename... Args>
  void operator()(const U& arg1, const Args&... args) {
    value+= arg1;
    operator()(args...);
  }
  T value;
};

std::vector<int> a = { 1, 2, 3, 4, 5 };
std::vector<int> b = { 1, 2, 3, 4, 5 };
std::vector<int> c = { 1, 2, 3, 4, 5 };
std::vector<int> d = { 1, 2, 3, 4, 5 };

Add<int> sum2 = for_each_N(a.begin(), a.end(), Add<int>(), b.begin());
Add<int> sum4 = for_each_N(a.begin(), a.end(), Add<int>(), b.begin(), c.begin(), d.begin());
Tagged as: No Comments
26Mar/150

use cppreference.com’s documentation in kdevelop

# from http://en.cppreference.com/w/Cppreference:Archives, download the Qt format: qch
wget http://upload.cppreference.com/mwiki/images/d/d2/qch_book_20141118.zip
# unzip it and copy to the dir, returned by:
qmake -query QT_INSTALL_DOCS
Filed under: Uncategorized No Comments
24Mar/150

generic linux youcompleteme install

# install vundle[1]
mkdir -p ~/.vim/bundle
cd  ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# edit your ~/.vimrc [2]
# open vim, and enter :PluginInstall
# YCM will be pulled but not installed:
cd ~
mkdir ycm_build
cd ycm_build
cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp -DUSE_SYSTEM_BOOST=ON -DUSE_SYSTEM_LIBCLANG=ON
make ycm_support_libs

# edit your global ~/.vim/.ycm_extra_conf.py [3]

[1] vundle: https://github.com/gmarik/Vundle.vim
[2] https://gist.github.com/cs0rbagomba/a06452fe7bd50cb39c8f
[3] https://gist.github.com/cs0rbagomba/49ded0d74042e95d74d1

Original YCM guide: https://github.com/Valloric/YouCompleteMe#full-installation-guide

Filed under: Uncategorized No Comments
20Mar/150

gdb command line history

edit ~/.gdbinit and add:

set history save
set history filename ~/.gdb_history
Filed under: Uncategorized No Comments
18Mar/150

gcov

# usual gcov run:
rm -rf COVERAGE_DIR && mkdir COVERAGE_DIR
lcov --directory BUILD_DIR -z
RUN_EXECUTABLE
lcov --directory BUILD_DIR --capture -b SOURCE_DIR -o lcov.info
genhtml --frames --legend -o COVERAGE_DIR lcov.info


# gcc  & gcov version mismatch:
geninfo: ERROR: PATH/FILE.gcno: reached unexpected end of file

# executable and *.gcda files are created in the different build runs
# graph file has been compiled again after binaries built.
Processing FILE.gcda
PATH/FILE.gcda:stamp mismatch with graph file

$ hexdump -e '"%x\n"' -s8 -n4 myclass.gcda
7ef26ee7
$ hexdump -e '"%x\n"' -s8 -n4 myclass.gcno
7ef26ee7

Filed under: Uncategorized No Comments
13Mar/150

format drive

parted -a optimal DEV
  rm NUM
  mkpart primary 0 -1
  set 1 boot on
  quit

mkfs.ext3 DEV1
Filed under: Uncategorized No Comments