Skip to content

Instantly share code, notes, and snippets.

@zzag
zzag / scheduler.cpp
Last active January 10, 2022 18:25
RealtimeKit example (Qt)
#include "scheduler.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusVariant>
#include <mutex>
#include <sched.h>
#include <sys/resource.h>
@zzag
zzag / PackageKit.md
Last active December 20, 2020 10:35
Pacman post transaction PackageKit hook

Create 90-refresh-packagekit.hook file in /etc/pacman.d/hooks/ with the following contents

[Trigger]
Type = Package
Operation = Install
Operation = Upgrade
Target = *

[Action]
#!/usr/bin/env python3
# Copyright (C) 2020 Vlad Zahorodnii
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@zzag
zzag / synergys@.service
Created August 6, 2019 13:23
/usr/lib/systemd/system/synergys@.service
[Unit]
Description=Synergy Server Daemon
After=network.target
[Service]
User=%i
ExecStart=/usr/bin/synergys --no-daemon --config /etc/synergy.conf --enable-crypto
Restart=on-failure
[Install]
@zzag
zzag / firefox-nightly.desktop
Last active June 6, 2024 02:20
Firefox Nightly desktop file
[Desktop Entry]
Version=1.0
Name=Firefox Nightly
GenericName=Web Browser
Comment=Browse the Web
Exec=/home/vlad/Applications/firefox-nightly/firefox --name firefox-nightly -P Nightly %u
Icon=/home/vlad/Applications/firefox-nightly/browser/chrome/icons/default/default128.png
Terminal=false
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
@zzag
zzag / reformat.sh
Last active March 11, 2018 16:22
Re-format source tree with clang-format
find . -iname *.h -o -iname *.c -o -iname *.cpp -o -iname *.hpp \
| xargs clang-format -style=file -i -fallback-style=none
@zzag
zzag / template_madness.cpp
Created March 3, 2018 22:27
template madness: factorial
#include <iostream>
using std::cout;
using std::endl;
template <int N>
struct factorial {
constexpr static int value = N * factorial<N-1>::value;
@zzag
zzag / gradient_checking.py
Created August 2, 2016 23:32
Gradient checking
import numpy as np
def eval_gradient_naive(f, x, dx=1e-4):
grad = np.zeros_like(x)
it = np.nditer(x, flags=['multi_index'], op_flags=['readwrite'])
while not it.finished:
ix = it.multi_index
@zzag
zzag / little-cheatsheet.txt
Created June 29, 2016 17:02
Vim commands cheat sheet
NORMAL:
- dd : cut line
- 10dd : cut 10 lines
- daw : cut word
- d2w : cut two words
- %d : cut all content
- y : copy
- yy : yank line
- 10yy : copy 10 lines
- p : paste after cursor
@zzag
zzag / torch-activate.fish
Created June 29, 2016 16:46
torch-activate for fish shell
function torch_activate()
set -gx TORCH_INSTALL_DIR $HOME
set -gx LUA_PATH $TORCH_INSTALL_DIR'/.luarocks/share/lua/5.1/?.lua;'$TORCH_INSTALL_DIR'/.luarocks/share/lua/5.1/?/init.lua;'$TORCH_INSTALL_DIR'/torch/install/share/lua/5.1/?.lua;'$TORCH_INSTALL_DIR'/torch/install/share/lua/5.1/?/init.lua;./?.lua;'$TORCH_INSTALL_DIR'/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua'
set -gx LUA_CPATH $TORCH_INSTALL_DIR'/.luarocks/lib/lua/5.1/?.so;'$TORCH_INSTALL_DIR'/torch/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so'
set -gx LD_LIBRARY_PATH $TORCH_INSTALL_DIR/torch/install/lib $LD_LIBRARY_PATH
set -gx DYLD_LIBRARY_PATH $TORCH_INSTALL_DIR/torch/install/lib $DYLD_LIBRARY_PATH
set -gx LUA_CPATH $TORCH_INSTALL_DIR'/torch/install/lib/?.so;' $LUA_CPATH
set -gx fish_user_paths $TORCH_INSTALL_DIR/torch/install/bin $fish_user_paths
end