Skip to content

Instantly share code, notes, and snippets.

@dansimau
dansimau / git-mc.sh
Created February 6, 2014 10:37
git helper script to quickly edit and resolve merge conflicts. See usage: https://gist.github.com/dansimau/8841861#comment-1000517
#!/bin/bash
#
# Helper script to quickly fix merge conflicts.
#
# dan@dans.im
# 2014-02-05
#
#
@dansimau
dansimau / README.md
Last active July 31, 2022 01:22
Tool for logging SSH sessions.

What is sshlog.sh

sshlog.sh logs all your SSH sessions to the specified destination directory so you can search/recall them later.

How to use

class DirtyBase(object):
def __init__(self, *a, **k):
super(DirtyBase, self).__init__(*a, **k)
self.dirty = False
def __setitem__(self, *a, **k):
self.mark_dirty()
super(DirtyBase, self).__setitem__(*a, **k)
#!/bin/bash
# Get last argument as the base filename
file=${!#}
if [ "$file" == "--version" ]; then
python --version
exit $?
fi
@dansimau
dansimau / tsv-to-excelcsv.py
Created November 22, 2013 14:25
Convert TSV to CSV.
import sys
import csv
tsvin = csv.reader(sys.stdin, dialect=csv.excel_tab)
csvout = csv.writer(sys.stdout, dialect=csv.excel)
for row in tsvin:
# Force all fields to be string-based (Excel specific)
for i, val in enumerate(row):
row[i] = '="%s"' % val
csvout.writerow(row)
@dansimau
dansimau / git-unmerged.py
Last active April 22, 2019 04:52
Report branches or commits that are not yet merged into master.
#!/usr/bin/python
"""
Report branches or commits that are not yet merged into master.
"""
import subprocess
from os.path import basename
# Merge/environment branches. These will be excluded from the
# "unmerged branches" list.
EXCLUDE_BRANCHES = ['staging', 'uat', 'production', 'master']
@dansimau
dansimau / README.md
Last active December 19, 2015 07:19
Python module for accessing data structures using JSON-like notation.

Trying out HHVM (JIT)

Following instructions to set up Wordpress (from http://www.hiphop-php.com/wp/?p=113):

# /usr/bin/hhvm --mode server --user www-data --config /etc/hhvm.hdf
/home/sgolemon/dev/hiphop-php/src/runtime/vm/translator/asm-x64.cpp:79 (makeExecable): mprotect @(nil) 32768 bytes failed (Cannot allocate memory)
/home/sgolemon/dev/hiphop-php/src/runtime/vm/translator/asm-x64.cpp:79 (makeExecable): mprotect @(nil) 32768 bytes failed (Cannot allocate memory)
Aborted (core dumped)

@dansimau
dansimau / grepurls.py
Created November 13, 2012 09:44
Recursive grep-like search for extracting URLs from a bunch of files
import os
import re
import sys
# Crazy URL regexp from Gruber
# http://daringfireball.net/2010/07/improved_regex_for_matching_urls
r = re.compile(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
# grep -r
for parent, dnames, fnames in os.walk(sys.argv[1]):
@dansimau
dansimau / test-md5-bin.lua
Created August 23, 2012 03:22
Testing performance of md5 hash calculation in lua vs node
require("md5")
local testname = "lua md5 sum hash test (binary)"
function test()
-- Create object hash
local object_key_plain = [[
"0.0.0.0",
80,
"www.example.com",