Skip to content

Instantly share code, notes, and snippets.

View manics's full-sized avatar
🇪🇺
🙂

Simon Li manics

🇪🇺
🙂
View GitHub Profile
@manics
manics / process-tree-monitor.py
Created March 20, 2014 17:25
Prints out a tree of processes, repeats after one second.
#!/usr/bin/env python
# Prints out a tree of processes with cpu and memory use
# Usage: process-tree-monitor pid [-v]
import psutil
from datetime import datetime
import sys
import time
@manics
manics / cpu-usage.py
Last active August 29, 2015 14:05
ASCII/terminal CPU usage graph. Bars are split into coloured blocks for each CPU if termcolor module is available, otherwise a single bar is shown
#!/usr/bin/env python
import math
import os
import psutil
import sys
import time
try:
import termcolor
TERMCOLORS = termcolor.COLORS.keys()
DROP TABLE IF EXISTS test_edges;
DROP TABLE IF EXISTS test_nodes;
CREATE TABLE test_nodes(id SERIAL PRIMARY KEY);
CREATE TABLE test_edges(
a INTEGER REFERENCES test_nodes(id), b INTEGER REFERENCES test_nodes(id));
INSERT INTO test_nodes(id) VALUES (0);
-- Create a graph with 100,000 nodes
@manics
manics / lastfm_matrix.py
Last active December 19, 2015 12:59
Create a simple HTML visualisation of similarity scores between last.fm users. Replace API_KEY with your Last.fm api key, and USERS_* with a list of usernames.
# Create a simple HTML visualisation of similarity scores between last.fm users.
# Replace API_KEY with your Last.fm api key, and USERS_* with a list of usernames.
import sys
import time
import urllib2
import xml.dom.minidom
api_key = API_KEY
@manics
manics / README.md
Last active April 29, 2016 21:40
Update Etcd SkyDNS with OpenStack instances

Openstack Etcd SkyDNS

A very simple polling agent that updates an Etcd database with SkyDNS entries for all OpenStack instances in a tenancy.

Example

docker run -d --name etcd quay.io/coreos/etcd \
    --listen-client-urls http://0.0.0.0:2379 \

--advertise-client-urls http://0.0.0.0:2379 --debug

@manics
manics / Celery_Task.py
Last active February 27, 2017 14:36
Example of running Celery Docker tasks in OMERO
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Celery_Task.py
This is a short demonstration of creating Celery Docker tasks in OMERO,
with direct read-only access to the ManagedRepository.
It is not secure, and should only be used where you trust users to have
read-access to the data of all other users.
@manics
manics / get-pg-stat-statements.sh
Created August 2, 2017 07:58
Get PostgreSQL pg_stat_statements as a CSV. Requires pg_stat_statements extension on the server
#!/bin/bash
# Requires pg_stat_statements extension on the server
# https://www.postgresql.org/docs/9.6/static/pgstatstatements.html
if [ $# -ne 1 ]; then
echo Usage: $(basename "$0") dbname
exit 1
fi
sudo -u postgres psql "$1" -c '
@manics
manics / idr-image.ipynb
Last active September 5, 2019 23:01
Example of fetching IDR image metadata
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@manics
manics / README.md
Last active September 6, 2019 19:37

Connect to OMERO, passing parameters as URL query parameters

Binder

This notebook requires the parameters host, username, passwd

If you already have a notebook opened you can pass the parameters by adding this query string to the URL in your browser:

?host='HOST'&username='USERNAME'&passwd='PASSWD'

or

@manics
manics / README.md
Last active September 10, 2019 18:56
Run a Jupyter Notebook on BinderHub non-interactively from the command line

Run a Jupyter Notebook on BinderHub non-interactively from the command line

The notebook should contain a cell starting with # Parameters:

Example:

./binderhub-exec.py \
    gist/manics/421f2927bb1dbdbc00754a7669eb3f69/master \
    idr-image.ipynb \

IMAGE_ID=4495402