Skip to content

Instantly share code, notes, and snippets.

@marczych
marczych / file-pager
Last active Jul 15, 2019
Bash script to open a file or URL in a pager
View file-pager
#!/usr/bin/env bash
set -euo pipefail
if [[ $# == 0 || $1 == "-h" || $1 == "--help" ]]; then
echo "Usage: $0 file"
exit 0
fi
file="$1"
View delete_merged_branches.sh
git branch -r --merged | egrep -v "(^\*|master|dev)" | sed -E 's#^.*origin/(.*)$#:\1#' | xargs git push origin
View gist:6422c4fd76f2ee015e4b
rsync -az --delete --exclude=.git -e 'ssh -i <identity file>' src user@host:dest
@marczych
marczych / gist:10524654
Last active Aug 29, 2015
Tmux git-scripts functions
View gist:10524654
#!/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/|.*$//')
@marczych
marczych / MyActivity.java
Last active Mar 9, 2016
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…
View MyActivity.java
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:3882918
Created Oct 13, 2012
Vim: Take the word under the cursor, append the current buffer's extension, and open it using find.
View gist:3882918
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.