Skip to content

Instantly share code, notes, and snippets.

@heathhenley
heathhenley / ansistrm.py
Created November 20, 2018 21:36 — forked from vsajip/ansistrm.py
Python logging: colourising terminal output
#
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
#
import ctypes
import logging
import os
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
color_map = {
@heathhenley
heathhenley / run_all_calibrate.py
Created July 15, 2019 12:15
Run all the cal files
import pathlib
import time
import calibrate
CALIBRATION_DIR = r"\\pvd\calibrationdata"
p = pathlib.Path(CALIBRATION_DIR)
import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(10)
_, _, patches = plt.hist(x, bins=3)
labels = ["label%d" % i for i in range(len(patches))]
for rect, label in zip(patches, labels):
height = rect.get_height()
plt.gca().text(rect.get_x() + rect.get_width() / 2, height, label,
ha='center', va='bottom')
import "golang.org/x/tour/pic"
func Pic(dx, dy int) [][]uint8 {
var pic [][] uint8
for x := 0; x < dx; x++ {
pic = append(pic, make([]uint8, dy))
for y := 0; y < dy; y++ {
pic[x][y] = uint8((x*x + y*y + x + y )/2)
}
}
@heathhenley
heathhenley / wordcount.go
Last active March 26, 2020 22:30
golang_tutorial_map_example
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
word_map := make(map[string]int)
for _, word := range strings.Fields(s) {
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
package main
import (
"image"
"image/color"
"golang.org/x/tour/pic"
)
type Image struct{}
package main
import (
"fmt"
"sync"
"time"
)
// SafeUrl is safe to use concurrently.
type SafeUrl struct {
@heathhenley
heathhenley / count_triplets.py
Last active April 10, 2020 02:33
A possible solution to count triplets HackerRank problem (https://www.hackerrank.com/challenges/count-triplets-1)
!/bin/python3
import collections
import math
import os
import random
import re
import sys
def countPairs(arr, r):
def fib(n):
if n < 2:
return 1
return fib(n-1) + fib(n-2)