Skip to content

Instantly share code, notes, and snippets.

View chrisma's full-sized avatar

Christoph Matthies chrisma

View GitHub Profile
@chrisma
chrisma / Reddit_sidebar_bookmarklet.html
Created December 18, 2014 17:44
Bookmarklet for toggling visibility of Reddit sidebar
<a href="javascript:$('div.side').toggle();void 0;">Toggle sidebar</a>
@chrisma
chrisma / unread_in_primary.txt
Created January 26, 2015 14:38
Show unread e-mails in primary inbox in Gmail
category:primary is:unread
@chrisma
chrisma / neo4j_cheatsheet.md
Last active October 1, 2019 16:18
Neo4J cheatsheet

Neo4J Cheatsheet

Refcard

http://neo4j.com/docs/2.1/cypher-refcard/

Database Exploration

List all labels of a node

labels(n)

List all node labels (and count them)

MATCH n

RETURN distinct labels(n), count(n) as count_n

@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 / fizzbuzz.py
Last active September 11, 2020 18:50
Fizzbuzz in too much detail
#! /usr/bin/env python3
# coding=utf-8
# Python version of
# http://www.tomdalling.com/blog/software-design/fizzbuzz-in-too-much-detail/
# Run it live at:
# https://www.pythonanywhere.com/gists/02d713164ca0f6882f50/fizzbuzz.py/ipython3/
### A Naïve Implementation
@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 / hex_to_rgb.py
Created June 9, 2015 09:53
Django templatetag to convert hex to RGB colors.
# USAGE:
# {% load file_the_templatetag_is_in %}
# {{ my_hex_color| hex_to_rgb }}
# {{ my_hex_color| hex_to_rgb:'rgba({r},{g},{b}, 0.5)' }}
# {{ my_hex_color| hex_to_rgb:'Components: r:{r},g:{g},b:{b}' }}
# adapted from https://github.com/guillaumeesquevin/django-colors
@register.filter(name='hex_to_rgb')
def hex_to_rgb(hex, format_string='rgb({r},{g},{b})'):
"""Returns the RGB value of a hexadecimal color"""
@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';