Skip to content

Instantly share code, notes, and snippets.

View chrisma's full-sized avatar

Christoph Matthies chrisma

View GitHub Profile
@chrisma
chrisma / more_inotify_files.sh
Created February 22, 2015 02:00
Allow inotify to watch more files
# Workaround for "There are too many directories in your application for changes in all of them to be monitored."
# message in Flask
echo fs.inotify.max_user_watches=100000 | sudo tee -a /etc/sysctl.conf; sudo sysctl -p
@chrisma
chrisma / all_functions.py
Last active August 29, 2015 14:20
Get all functions within current module
# Run it live at
# https://www.pythonanywhere.com/gists/9671392e68fc0fff324c/all_functions.py/ipython3/
import inspect, sys
def func1():
pass
def func2():
pass
@chrisma
chrisma / numbers_hap.py
Created May 5, 2015 13:20
Happy number checking in Python (recursively)
#! /usr/bin/env python3
# coding=utf-8
# Check if a number is happy or sad
# http://en.wikipedia.org/wiki/Happy_number
def happy(number, past = None):
def happy_calc(number):
return sum((int(digit)**2 for digit in str(number)))
@chrisma
chrisma / barebones_dollar.js
Created June 15, 2015 09:55
JQuery's '$' selector syntax without the rest of JQuery..
function $(q, parent) {
parent = parent || document;
//convert DOM NodeList into array, so that e.g. 'forEach' can be called.
return Array.prototype.slice.call(parent.querySelectorAll(q));
}
@chrisma
chrisma / data_fetching_service_callback.js
Last active August 29, 2015 14:23
Clean (i.e. callback-free) data-fetching service (AJAX) in AngularJS
/*
* Using callbacks to set scope variables (Not as nice)
*/
var app = angular.module("MyApp", []);
app.factory('sourceService', function($http, $q, $log) {
return {
get : function(){
var endpoint = 'data.json';
@chrisma
chrisma / footnotes.tex
Created July 6, 2015 09:53
Declare LateX footnotes outside of text, not inline
\documentclass{article}
\usepackage{sepfootnotes}
\begin{document}
% \sepfootnotecontent needs to be defined before \sepfootnote
\sepfootnotecontent{a}{The footnotetext outside of the paragraph.}
A long sentence\sepfootnote{a} that I don't want broken by inline footnotes.
\end{document}
@chrisma
chrisma / enumerate_style.tex
Created July 6, 2015 21:45
Change enumerate Latex style
\documentclass{article}
\begin{document}
\begin{enumerate}
% Redefine first level style to R1:
% \labelenumii would be second level
\renewcommand{\labelenumi}{\textbf{R\arabic{enumi}}:}
\item Question 1
\item Question2
\end{enumerate}
@chrisma
chrisma / helpers.tex
Created January 20, 2016 10:51
Commands I tend to use for new LaTeX documents
% Enquote stuff nicely
\newcommand{\enquote}[1]{``#1''}
% Superscripts in text
\newcommand{\up}[1]{\ensuremath{^{\textrm{\small#1}}}}
@chrisma
chrisma / profile_script.sh
Created March 4, 2016 13:38
Profile Python script
# sorting options: https://docs.python.org/3/library/profile.html#pstats.Stats.sort_stats
FILE="file.py"; python -m cProfile -s cumulative $FILE > profile && less profile
@chrisma
chrisma / cheat_sheet.sh
Created March 20, 2016 10:12
Terminal Cheat Sheet - commonly used commands
# Find and delete files
find . -type f -name "trash" -delete