Skip to content

Instantly share code, notes, and snippets.

@marczych
marczych / gist:3882918
Created October 13, 2012 02:03
Vim: Take the word under the cursor, append the current buffer's extension, and open it using find.
nnoremap <silent> <C-o> :call FindFile()<CR>
function! FindFile()
" Get the word under cursor.
let cursorWord = expand("<cword>")
" Get the current file name and keep only the extension.
let currentFile = expand("%")
let extPos = stridx(currentFile, ".")
" Append an extension only if the current file has an extension.
@marczych
marczych / MyActivity.java
Last active April 12, 2023 12:54
This is a workaround for `android:showAsAction="withText"` not displaying text on narrow layouts e.g. in portrait on phones. This uses styles found in ActionBarSherlock so it matches the native styling. I tested it with ABS v4.4.0 but earlier versions are probably compatible.Note: This should only be used if you absolutely have to display the te…
public class MyActivity extends Activity {
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Trigger onOptionsItemSelected for the custom menu item because it doesn't
// happen automatically.
final MenuItem item = menu.findItem(R.id.button_id);
barcodeItem.getActionView().setOnClickListener(new OnClickListener() {
@Override
@marczych
marczych / gist:10524654
Last active August 29, 2015 13:59
Tmux git-scripts functions
#!/bin/sh
# Convenience functions to set the tmux session name based on branches/pull
# numbers and switches branches based on the session name.
#
# Depends on tmux and https://github.com/iFixit/git-scripts.
# (feature|hotfix) switch based on the session name.
function tswitch {
BRANCH=$(tmux display-message -p '#S' | sed 's/|.*$//')
rsync -az --delete --exclude=.git -e 'ssh -i <identity file>' src user@host:dest
git branch -r --merged | egrep -v "(^\*|master|dev)" | sed -E 's#^.*origin/(.*)$#:\1#' | xargs git push origin
@marczych
marczych / file-pager
Last active July 15, 2019 17:14
Bash script to open a file or URL in a pager
#!/usr/bin/env bash
set -euo pipefail
if [[ $# == 0 || $1 == "-h" || $1 == "--help" ]]; then
echo "Usage: $0 file"
exit 0
fi
file="$1"