Skip to content

Instantly share code, notes, and snippets.

View prepare_headers_bfx
import json
import base64
import hashlib
import hmac
def _prepare_headers(payload, api_key, api_secret):
# payload = parameters-dictionary -> JSON encode -> base64
payload_json = json.dumps(payload)
payload_encoded = base64.encodestring(payload_json)
# signature = HMAC-SHA384(payload, api-secret) as hexadecimal
View json-all-the-way
{
"metadata": {
"name": "",
"signature": "sha256:5835de2e10cb99253cfa1841c86b02e6b9ee8b2fb21e513bbaec771e6e006c1b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
View pagination
{% if is_paginated %}
<div class="col-md-offset-4">
<ul class="pagination pagination-centered">
{% if page_obj.has_previous %}
<li><a href="?page=1"><<</a></li>
<li><a href="?{{queries.urlencode}}&amp;page={{ page_obj.previous_page_number }}"><</a></li>
{% endif %}
{% for i in paginator.page_range %}
<li {% if page_obj.number == i %} class="active" {% endif %}><a href="?{{queries.urlencode}}&amp;page={{i}}">{{i}}</a></li>
View intersection_test.py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import time
data = []
for n_elements in [100, 1000, 10000, 100000]:
a = range(n_elements)
sa = set(a)
b = np.array(a) + 50
@mattions
mattions / .screenrc
Created May 9, 2015
Sane screen rc default
View .screenrc
hardstatus alwayslastline '%{= G}[ %{G}%H %{g}][%= %{= w}%?%-Lw%?%{= R}%n*%f %t%?%{= R}(%u)%?%{= w}%+Lw%?%= %{= g}][ %{y}Load: %l %{g}][%{B}%Y-%m-%d %{W}%c:%s %{g}]'
startup_message off
termcapinfo xterm* ti@:te@
backtick 1 5 5 true
termcapinfo rxvt* 'hs:ts=\E]2;:fs=\007:ds=\E]2;\007'
View purge_old_kernels.sh
#!/bin/sh
#
# purge-old-kernels - remove old kernel packages
# Copyright (C) 2012 Dustin Kirkland <kirkland@ubuntu.com>
#
# Authors: Dustin Kirkland <kirkland@ubuntu.com>
# Kees Cook <kees@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
View save_more_extension.py
def _save_more_extensions(filename, extensions=['png', 'svg', 'pdf']):
for ext in extensions:
comp_filename = "{0}.{1}".format(filename, ext)
plt.savefig(comp_filename, dpi=300)
print "Saved plot: {0}".format(comp_filename)
View deleting_line_plot_matplotlib.py
# Deleting a line in matplot lib
fig = figure()
ax = fig.add_subplot(111)
x = linspace(0,10)
plot(x, sin(x), label='sin')
plot(x, cos(x), label='cos')
# Deleting the last one
del ax.lines[1]
draw() # updating the fig
View create_new_dir_by_day.py
def create_new_dir(self, prefix="./", root="Sims"):
"""
Create the directory where to put the simulation
"""
self.dirRoot = os.path.join(prefix, root)
today = datetime.date.today()
free = False
index = 0
View saving_compressed_array. Maybe useful later on.
def save_node(self, h5file_holder, group_path, section_name, variables,
detail=''):
"""Save a node to the h5file.
h5file_holder: The holder of the h5file
group_path: Where in the hierarchy the leaf has to be saved
section_name: The name of the section which the variables belong to
variables: The dictionary of the variable
"""
found = False
target_group = None
You can’t perform that action at this time.