Skip to content

Instantly share code, notes, and snippets.

@zertrin
zertrin / etherpad-lite_list_pads.sh
Created January 1, 2013 23:41
One-liner to retrieve the list of all etherpad-lite's pad names in the database
#!/bin/sh
mysql -u etherpad-lite -p etherpad-lite -e 'select store.key from store' \
| grep -Eo '^pad:[^:]+' \
| sed -e 's/pad://' \
| sort \
| uniq -c \
| sort -rn \
| awk '{if ($1!="2") {print $2 }}'
@zertrin
zertrin / bar2.m
Created January 14, 2013 14:29
BAR2 Generalized Bar graph (Stacked, Groups, Clustered, Floating, Mixed)
function bar2(varargin)
%BAR2 Generalized Bar graph (Stacked, Groups, Clustered, Floating, Mixed)
% BAR2(X,Y) draws the columns of the M-by-N-by-Q matrix Y as N main
% categories with (M/2) subcategories (as default, see below) and Q
% simultaneous data sets with same X coordinates displayed on the
% same graph
%
% For MIXED charts, use input as a cell with each row containing the
% information for each type of chart, see example below
%
@zertrin
zertrin / make_sure_path_exists.py
Created January 28, 2013 09:40
Make sure path exists, trying to create the path and raising exception in case of problem (except when it's just because the path already exist) From http://stackoverflow.com/questions/273192/python-best-way-to-create-directory-if-it-doesnt-exist-for-file-write/5032238#5032238
import os
import errno
def make_sure_path_exists(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
from datetime import datetime, timedelta
def datetime2matlabdn(dt):
ord = dt.toordinal()
mdn = dt + timedelta(days = 366)
frac = (dt-datetime(dt.year,dt.month,dt.day,0,0,0)).seconds / (24.0 * 60.0 * 60.0)
return mdn.toordinal() + frac
@zertrin
zertrin / getpage.py
Created February 12, 2013 14:17
Helper function to grab web pages with urllib2. Returns content of the page if retrieval was successful, None otherwise.
import urllib2
def getpage(url):
"""
Helper function to grab web pages with urllib2
returns content of the page if retrieval was successful, None otherwise
"""
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0')
@zertrin
zertrin / gist:5146429
Last active December 14, 2015 20:48
Prints the content of input file deduplicating the lines based on the content of the 4th column
awk '!_[$4]++' file
@zertrin
zertrin / gist:5152760
Created March 13, 2013 14:41
Clear all but breakpoints
temporaryBreakpointData=dbstatus('-completenames');
clear functions;
dbstop(temporaryBreakpointData);
clear global;
clear variables;
@zertrin
zertrin / getAllFiles.matlab
Last active December 16, 2015 22:39
Function that searches recursively through all subdirectories of a given directory, collecting a list of all file names matching a given regexp pattern it finds. ( from http://stackoverflow.com/questions/2652630/how-to-get-all-files-under-a-specific-directory-in-matlab )
function fileList = getAllFiles(dirName, pattern)
% Example: filelistCSV = getAllFiles(somePath,'\d+_\d+_\d+\.csv');
dirData = dir(dirName); %# Get the data for the current directory
dirIndex = [dirData.isdir]; %# Find the index for directories
fileList = {dirData(~dirIndex).name}'; %'# Get a list of the files
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),... %# Prepend path to files
fileList,'UniformOutput',false);
matchstart = regexp(fileList, pattern);
@zertrin
zertrin / imagescwithnan.matlab
Created May 10, 2013 10:30
IMAGESC with NaNs assigning a specific color to NaNs
function [h, hcb] = imagescwithnan(a, cm, nanclr, hidenan, clims)
% IMAGESC with NaNs assigning a specific color to NaNs
% Usage example:
% a = peaks;
% a(a < 0) = nan;
% imagescwithnan(a, hot, [0 1 1]) % [0 1 1] is cyan
% or
% imagescwithnan(a, hot, [0 1 1], true) % hide NaN color from
% % the colorbar
% or
@zertrin
zertrin / vimdiff.md
Last active December 17, 2015 18:28 — forked from mattratleph/vimdiff.md

vimdiff cheat sheet

##vimdiff commands

]c :        - next difference
[c :        - previous difference
do          - diff obtain
dp          - diff put
zo          - open folded text

zc - close folded text