Skip to content

Instantly share code, notes, and snippets.

View matbra's full-sized avatar

Matthias Brandt matbra

  • Bremen, Germany
View GitHub Profile
@pkienzle
pkienzle / zotscan.py
Last active December 13, 2023 05:39
scan zotero database for missing attachments
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import glob
import shutil
import sqlite3
from os.path import join as joinpath, expanduser, exists, isabs, realpath
@tomhopper
tomhopper / plot_aligned_series.R
Last active June 25, 2023 17:36
Align multiple ggplot2 graphs with a common x axis and different y axes, each with different y-axis labels.
#' When plotting multiple data series that share a common x axis but different y axes,
#' we can just plot each graph separately. This suffers from the drawback that the shared axis will typically
#' not align across graphs due to different plot margins.
#' One easy solution is to reshape2::melt() the data and use ggplot2's facet_grid() mapping. However, there is
#' no way to label individual y axes.
#' facet_grid() and facet_wrap() were designed to plot small multiples, where both x- and y-axis ranges are
#' shared acros all plots in the facetting. While the facet_ calls allow us to use different scales with
#' the \code{scales = "free"} argument, they should not be used this way.
#' A more robust approach is to the grid package grid.draw(), rbind() and ggplotGrob() to create a grid of
#' individual plots where the plot axes are properly aligned within the grid.
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@num3ric
num3ric / interleave.cpp
Last active December 2, 2020 21:58
In-place array interleaving
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <assert.h>
typedef std::chrono::high_resolution_clock Clock;
template<typename T>
@pichenettes
pichenettes / gist:1788715
Created February 10, 2012 10:47
Least square regression of complex amplitudes onto a synthetic signal subspace for an EDS+50 Hz hum model
import numpy
import pylab
delta = 0.01
omega = 0.05
omega_noise = 0.2
A = 5
A_noise = 0.2
phi = 0.8
N = 1000
@mmaz
mmaz / TabletRotation.sh
Created June 21, 2011 21:37
Rotate screen in Ubuntu for a Lenovo X60
#!/bin/bash
rotation=`xrandr --query --verbose | grep "LVDS1" | awk '{print $5}'`
if [ $rotation = "normal" ]
then
xsetwacom set "Serial Wacom Tablet stylus" Rotate half
xrandr -o inverted
else
xsetwacom set "Serial Wacom Tablet stylus" Rotate none
xrandr -o normal
@zonca
zonca / oneoverfsim.py
Created May 18, 2011 22:21
Pink noise
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
def one_over_f(f, knee, alpha):
desc = np.ones_like(f)
desc[f<KNEE] = np.abs((f[f<KNEE]/KNEE)**(-alpha))
desc[0] = 1
return desc
@artisonian
artisonian / simple_gridfs_server.py
Created July 27, 2010 19:24
A simple GridFS server built with Flask
from flask import Flask, request, redirect, url_for, make_response, abort
from werkzeug import secure_filename
from pymongo import Connection
from pymongo.objectid import ObjectId
from gridfs import GridFS
from gridfs.errors import NoFile
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
DB = Connection().gridfs_server_test
FS = GridFS(DB)