Skip to content

Instantly share code, notes, and snippets.

View dmerejkowsky's full-sized avatar
🍵
418 - I'm a teapot

Dimitri Merejkowsky dmerejkowsky

🍵
418 - I'm a teapot
View GitHub Profile
@dmerejkowsky
dmerejkowsky / qisys.script.py
Last active January 26, 2016 21:48
Clever use of argparse
# in qibuild/actions/build.py
""" build stuff """
def configure_parser(parser):
qibuild.parser.build_parser(parser)
parser.add_argument("target")
def do(args):
build(args.build_type, arg.target)
@dmerejkowsky
dmerejkowsky / test.py
Created January 27, 2016 13:01
py.test rocks
# in test_qibuild_configure.py
def test_qibuild_configure(tmpdir):
# do stuff in tmpdir
assert rc == 0
@dmerejkowsky
dmerejkowsky / tests.py
Last active January 27, 2016 13:45
unittest sucks
# in test_qibuild_configure.py
class QiBuildTestCase(unittest.TestCase, ActionTestCase):
def setUp(self):
self.tmpdir = tmpfile.mkdtemp("test-qibuild-")
def test_configure(self):
# do stuff in tmpdir
rc = ...
self.assertEquals(rc, 0)
@dmerejkowsky
dmerejkowsky / conftest.py
Last active January 27, 2016 22:43
Using py.test fixtures
# in qisys.sh
def get_config_path():
return get_path(".config")
def get_share_path():
return get_path(".local/share")
def get_path():
# read XDG
@dmerejkowsky
dmerejkowsky / git-history-stats.py
Last active February 29, 2016 13:08
Get git history statistics
import sys
import subprocess
import packaging.version
import tabulate
out = subprocess.check_output(["git", "tag"]).decode("UTF-8")
current_branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
if not current_branch:
sys.exit("Not on a branch")
@dmerejkowsky
dmerejkowsky / source-date-epoch-from-git.sh
Created March 16, 2016 12:18
source-date-epoch-from-git
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
# This sets SOURCE_DATE_EPOCH to the date of the last commit, (it's even better if it's a
# signed tag of course), which is perfect for reproducible builds.
# See here for more info : https://reproducible-builds.org/
@dmerejkowsky
dmerejkowsky / call-private.java
Created March 18, 2016 23:16
Calling private methods in Java
import java.lang.reflect.Method;
Foo foo = new Foo();
Method method = Foo.class.getDeclaredMethod("private")
method.setAccessible(true);
method.invoke(foo);
" One argument:
function! Foo(foo)
" Do something with a:foo
endfunction
command! -nargs=1 -complete=file Foo :call Foo("<args>") " <- note the quotes
" Two arguments:
function! Foo2(foo, bar)
" Do something with a:foo and a:bar
endfunction
@dmerejkowsky
dmerejkowsky / logs
Last active April 20, 2016 14:28
jenkins strange return code on Windows for CreateProcess
# From the command line:
c:\pouet.exe
segfault
Exit code: 0xc0000005
# From a jenkins slave connected as a Windows service:
c:\Users\xxxx\jenkins\workspace\pouet>C:\pouet.exe
segfault
Exit code: 0xff
@dmerejkowsky
dmerejkowsky / autorefresh-neovim-chromium.py
Last active April 20, 2016 16:16
Autorefresh chromium from a neovim key binding
#!/usr/bin/env python
""" Usage:
* Start neovim with NVIM_LISTEN_ADDRESS=/tmp/neovim
* Install selenium and neovim Python packages from pypi
* Run autorefresh URL
* In neovim, map a kep to send the event:
nnoremap ,m :w<cr>:call rpcnotify(0, "refresh")<cr>