Skip to content

Instantly share code, notes, and snippets.

View rafi's full-sized avatar

Rafael Bodill rafi

View GitHub Profile
@rafi
rafi / convert.vim
Created October 6, 2014 12:23
Atlassian JIRA markup to Markdown. Oh the horror! Inspiration: https://github.com/FokkeZB/J2M
function! s:convert_to_markdown(txt)
let txt = a:txt
let txt = substitute(txt, 'h\(\d\+\)\. ', '\=repeat("#", submatch(1))." "', 'g')
let txt = substitute(txt, '{code\(:\([a-z]\+\)\)\?}', '```\2', 'g')
let txt = substitute(txt, '{{\([^}\n]\+\)}}', '`\1`', 'g')
let txt = substitute(txt, '\*\([^\*\n]\{-}\)\*', '\*\*\1\*\*', 'g')
let txt = substitute(txt, '_\([^_\n]\{-}\)_', '\*\1\*', 'g')
let txt = substitute(txt, '\s\zs-\([^-\n]\{-}\)-', '~~~\1~~~', 'g')
let txt = substitute(txt, '+\([^+\n]\+\)+', '<ins>\1</ins>', 'g')
let txt = substitute(txt, '\^\([^\^\n]\+\)\^', '<sup>\1</sup>', 'g')
@rafi
rafi / syntastic.vim
Last active August 29, 2015 14:07
syntastic/syntax_checkers/html/tidy.vim (Strip mustache tags out of HTML content to ease HTMLTidy's errors)
let g:syntastic_html_tidy_ignore_errors = [
\ '<html> attribute "lang" lacks value',
\ '<a> attribute "href" lacks value',
\ 'trimming empty <span>',
\ 'trimming empty <h1>'
\ ]
@rafi
rafi / git-hook.sh
Last active August 29, 2015 14:06
Git hooks maintenance
# Iterate and delete all hook files from git projects and submodules (only if there's ".git" in path)
find . -name 'post-*' | grep 'hooks/' | grep '.git' | sed 's/hooks\/.*$/hooks/g' | while IFS= read -r dir; do rm $dir/*; done;
# Copy your git template's hooks into all projects and submodules (only if there's ".git" in path)
find . -name 'hooks' -type d | grep '.git' | while IFS= read -r dir; do cp ~/.config/git/template/hooks/* $dir/; done;
# Copy your git template's hooks into a single project
cp ~/.config/git/template/hooks/* .git/hooks/
@rafi
rafi / siren.go
Created July 16, 2014 10:22
Israel siren alert notifier implementation in PHP, Go and Python. Go and Python just parse.
package main
// Credits: http://stackoverflow.com/a/24683083/351947
import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"unicode/utf16"
@rafi
rafi / provision-debian.yml
Created July 10, 2014 13:15
Ansible playbook: Provision Debian
---
- name: Provision | Bootstrapping machines
hosts: all
sudo: yes
roles:
- base/debian
- base/common
- system/supervisor-debian
@rafi
rafi / deploy.yml
Last active August 10, 2019 11:51
Ansible prepare a detached git repository and deploy
# -----------------------------------------------
# ENSURE GIT REPOSITORIES
- name: Git | Ensure server repository
sudo_user: git
git: repo={{ upstream }}
dest={{ repo_dir }}
bare=yes
update=no
tags: git
@rafi
rafi / Auth.php
Created July 8, 2014 09:33
Minimal Auth helper for Kohana
<?php
/**
* Auth helper
*
* @package Kohana/Auth
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
@rafi
rafi / install.sh
Created July 3, 2014 12:49
setup msmtp and php
apt-get install msmtp ca-certificates
vim /etc/msmtprc
# Set defaults.
defaults
# Enable or disable TLS/SSL encryption.
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
@rafi
rafi / .psqlrc
Created June 10, 2014 08:03
psql startup file
-- vim: se ft=psql :
------------------------------------------------------------------------------
-- sources and inspiration: --
-- http://opensourcedbms.com/dbms/psqlrc-psql-startup-file-for-postgres/ --
-- http://www.craigkerstiens.com/2013/02/21/more-out-of-psql/ --
-- https://github.com/dlamotte/dotfiles/blob/master/psqlrc --
------------------------------------------------------------------------------
\set QUIET ON
@rafi
rafi / generate_pl.sh
Last active June 4, 2018 18:54
Generate a playlist from a plain text file with songs. Using beets database to query file paths
#!/bin/bash
music_path="/mnt/media/music"
while read line
do
song=$(echo $line | sed 's/(.*)//g')
artist=$(echo ${song% - *} | sed 's/ *$//')
title=$(echo ${song#* - } | sed 's/ *$//')
if [ -n "$title" ]; then