Skip to content

Instantly share code, notes, and snippets.

View iver56's full-sized avatar
🎯
Writing Python code every day

Iver Jordal iver56

🎯
Writing Python code every day
  • Nomono
  • Trondheim, Norway
  • X @iver56
View GitHub Profile
@iver56
iver56 / gfx
Last active September 26, 2015 21:47
IT3105: Graphics class for visualizing a 2D grid. Useful when implementing the A* algorithm. Uses pygame.
import sys, pygame
pygame.init()
class Gfx(object):
"""
This class takes care of drawing the state of the search to a window using pygame
"""
size = width, height = 960, 540
@iver56
iver56 / test_huge.txt
Created October 5, 2015 21:19
A* navigation problelm
(1600,1200)
(0,0) (1346,260)
(18,50,330,918)
(46,960,184,172)
(220,1060,136,140)
(388,0,42,1178)
(246,984,156,56)
(500,938,194,262)
(606,166,402,622)
(1088,146,62,1028)
@iver56
iver56 / A* navigation problem
Created October 5, 2015 21:24
test_large.txt
(800,600)
(0,0) (673,130)
(14,25,165,459)
(23,480,92,86)
(110,530,68,70)
(194,0,21,589)
(123,492,78,28)
(250,469,97,131)
(303,83,201,311)
(544,73,31,514)
@iver56
iver56 / gist:796ad44194278790eea5
Created October 23, 2015 23:32
Dump the sql that django generates
import sqlparse
from django.db import connection
from django.core.signals import request_finished
def finished(sender, **kwargs):
for query in connection.queries:
print "\n" + "(" + query['time'] + " s) " + sqlparse.format(query['sql'], reindent=True, keyword_case="upper") + "\n"
if len(connection.queries) > 0:
print "NUMBER OF DB QUERIES FOR THIS REQUEST:", len(connection.queries)
request_finished.connect(finished)
@iver56
iver56 / gist:5c5c0e16a6f504e207c7
Last active November 7, 2015 14:04
Install CUDA 7.0 on Amazon EC2 g2.2xlarge running Ubuntu 14.04 trusty
sudo apt-get update
sudo apt-get -y dist-upgrade
# /boot/grub/menu.lst keep the local version. (or maybe not? replacing it could maybe be a good idea, and could avoid some of the hassle below)
sudo apt-get install -y gcc g++ gfortran build-essential git wget linux-image-generic libopenblas-dev python-dev python-pip python-nose python-numpy python-scipy linux-headers-generic-lts-trusty linux-source
# sudo apt-get install linux-headers-`uname -r`
sudo rm /boot/grub/menu.lst
sudo update-grub
@iver56
iver56 / gist:5f6a6dc5cdd7fc102dd4
Created November 21, 2015 23:10
Install CUDA on Amazon EC2 g2.2xlarge instance
sudo apt-get update
sudo apt-get -y dist-upgrade
sudo apt-get install -y gcc g++ gfortran build-essential linux-image-generic libopenblas-dev python-nose python-numpy python-scipy linux-headers-generic-lts-trusty linux-source
sudo rm /boot/grub/menu.lst
sudo update-grub
wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run
@iver56
iver56 / log_confusion_matrix.py
Last active October 29, 2019 17:10
Calculate and plot a confusion matrix, and then log it as an artifact in MLflow
import matplotlib.pyplot as plt
import mlflow
import numpy as np
from sklearn import metrics
def plot_confusion_matrix(
cm, class_names, title="Confusion matrix", cmap=plt.cm.Blues, normalize=False
):
"""
import os
import re
import subprocess
import tempfile
import uuid
from pathlib import Path
import numpy as np
from scipy.io.wavfile import write
@iver56
iver56 / compare-sunscreen-position.js
Last active June 5, 2024 06:40
HomeyScript for checking the position of a sunscreen connected to e.g. Fibaro Roller Shutter 3 or Walli Roller Shutter
/*
* This script is meant to be used in a Homey Flow with the
* 'Run a script with an argument' in the 'And'-column.
* The argument must be the name of the device, then a less than or greater than character (< or >) and finally a number between 0 and 1, e.g. "Zip Nord Venstre<0.5" (note: no spaces around the < or > character!)
*/
if (typeof args[0] !== 'string') {
throw new Error('This script must be run from a Flow!');
}
@iver56
iver56 / is-tibber-price-unresponsive.js
Created October 22, 2022 07:06
HomeyScript for "And" card that checks whether power price from Tibber is outdated
/*
* This script is meant to be used in a Homey Flow as an 'And' card.
*/
let sensorName = 'Relativ Strømpris'
log(`sensorName: ${sensorName}`);
// Get all devices
const devices = await Homey.devices.getDevices();