Skip to content

Instantly share code, notes, and snippets.

@kennethho
kennethho / gist:e280e1b020603bed01c0650d0b9bed33
Created June 2, 2017 06:57
s/gedit/sublime/ - sublime as default text editor
( head -n 1 /usr/share/applications/defaults.list && ack --match '^(?<mimetype>.+)=gedit.desktop$' --output '$+{mimetype}=sublime-text.desktop' /usr/share/applications/defaults.list ) | tee ~/.local/share/applications/defaults.list
@kennethho
kennethho / termux-sudo.sh
Last active October 16, 2021 05:26
Sudo for Termux
#!/data/data/com.termux/files/usr/bin/bash
#set -x
SUDO_SH=/data/data/com.termux/files/usr/bin/sh
QUOTED_SUDO_ARGS=$(printf '%q' $"$(printf '%q ' "$@")")
#QUOTED_SUDO_ARGS=$(printf '%q ' \"$@\")
printf '%s\n' "$QUOTED_SUDO_ARGS"
SU_C_ARGS=("LD_LIBRARY_PATH=$PREFIX/lib" "$SUDO_SH" "-c" "$QUOTED_SUDO_ARGS")
@kennethho
kennethho / draft.txt
Last active August 29, 2015 13:56 — forked from evanzillians/draft.txt
thor
├── contrib
│   ├── bar
│   └── foo
├── include
│   └── thor
│   ├── lib-1
│    │   └── hdr-1.h // names in thor::lib-1
│   └── lib-2
│   └── hdr-2.h // names in thor::lib-2
@kennethho
kennethho / m_days.c
Last active December 18, 2015 18:59 — forked from moskytw/m_days.c
#include <stdio.h>
#define NUM_OF_ELEMENTS(array) (sizeof(array)/sizeof(array[0]))
main() {
int ys[] = {2011, 2012, 2100, 2400};
int i = 0, m = 0;
for(i = 0; i < NUM_OF_ELEMENTS(ys); i++) {
// ref: https://plus.google.com/u/0/111121989384217966500/posts/LjSZjmKGpjj
// Tested with gcc 4.6.3
// $ g++ -std=c++0x THISFILE && a.out
#include <cassert>
#include <type_traits>
using namespace std;
@kennethho
kennethho / gist:3690842
Created September 10, 2012 13:14
Memory layout of STL linked list node
struct _List_node_base
{
_List_node_base* _M_next;
_List_node_base* _M_prev;
// ....
};
template<typename _Tp>
struct _List_node : public __detail::_List_node_base
{
// $ g++ -std=c++0x filter.cpp
#include <iterator>
#include <algorithm>
template <class Sequence, class Predicate>
Sequence filter(const Sequence& seq, Predicate pred)
{
Sequence result;
std::copy_if(begin(seq), end(seq), back_inserter(result), pred);
return result;
$ ./balad -h
LBS mode usage:
balad [OPSIONS...] --lsb LBS-HOST:LBS-PORT...
RBS mode usage:
balad [OPSIONS...] --rsb RBS-HOST:RBS-PORT:PROTOCOL-LEVEL...
Allowed options:
-h [ --help ] Produce this help message and exit
-c [ --concurrency ] arg (=1) Concurrency (number of threads)
-b [ --buffer ] arg (=1024) Size of session buffer in bytes
void handle_read(const sys::error_code& error,
size_t bytes_transferred)
{
if(error)
{
delete this;
return;
}
async_write(