Skip to content

Instantly share code, notes, and snippets.

@dansimau
dansimau / README.md
Last active December 19, 2015 07:19
Python module for accessing data structures using JSON-like notation.
@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 / 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)
#!/bin/bash
# Get last argument as the base filename
file=${!#}
if [ "$file" == "--version" ]; then
python --version
exit $?
fi
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)
@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

@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 / emoify.html
Created March 5, 2014 10:33
Instantly add emoji to any web app.
<script src="https://raw.github.com/hassankhan/emojify.js/master/emojify.min.js"></script>
<script>
(function() {
// Config
emojify.setConfig({
img_dir : '/emoji',
ignored_tags : {
'SCRIPT' : 1,
'TEXTAREA': 1,
'A' : 1,
@dansimau
dansimau / timeout-server.py
Created March 26, 2014 08:49
HTTP server that accepts connections and then hangs. Used to simulate and test slow API connections.
#!/usr/bin/python
import sys
import time
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(s):
while True:
time.sleep(1000)
@dansimau
dansimau / revert-lights-out.py
Created January 3, 2015 12:27
Undo a Mac theme stuck in dark mode due to https://github.com/samturner/lights-out
from Foundation import CFPreferencesSetValue
from Foundation import CFNotificationCenterPostNotification
from Foundation import CFNotificationCenterGetDistributedCenter
from Foundation import kCFPreferencesAnyApplication
from Foundation import kCFPreferencesCurrentUser
from Foundation import kCFPreferencesCurrentHost
# Remove offending preference
CFPreferencesSetValue('AppleInterfaceStyle', None, kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser, kCFPreferencesCurrentHost)