Skip to content

Instantly share code, notes, and snippets.

@kevindoran
kevindoran / rg_discrepancy.py
Created September 6, 2023 13:39
red_or_green_discrepancy
def filter_in_box(ps, l, u):
"""Fiter in points that lie inside rectangle."""
res = ps[(ps[:, 0] >= l[0]) & (ps[:, 0] < u[0]) & (ps[:, 1] >= l[1]) & (ps[:, 1] < u[1])]
return res
def discrepancy(ps, l, u, method):
disc = scipy.stats.qmc.discrepancy(
scipy.stats.qmc.scale(filter_in_box(ps, l, u), l, u, reverse=True),
method=method)
return disc
@kevindoran
kevindoran / single.html
Last active January 24, 2023 09:57
Hugo single page template for Anki cards
{{ define "head" }}
<link rel="stylesheet" href="{{ "css/anki.css" | relURL }}">
<script>
function toggleCard() {
btn = document.getElementById("toggle-card-btn")
if(btn.textContent == "Show Answer") {
document.getElementsByClassName("anki-front")[0].style.display = "none";
document.getElementsByClassName("anki-back")[0].style.display = "block";
btn.textContent = "Hide Answer";
} else {
@kevindoran
kevindoran / anki_to_html.py
Last active June 8, 2021 16:23
Export Anki decks as webpages (targeting Hugo)
import anki
import anki.collection
import anki.exporting
import datetime
import os
import re
import cssutils
import shutil
import logging
@kevindoran
kevindoran / Dragon.java
Created June 1, 2013 03:03
Dragon class used to demonstrate security issues when using Java serialization.
public Dragon(double wingSpan, double name, SpeedCalculator speedCalculator) {
// There are no input checks this time!
this.wingSpan = wingSpan;
this.name = name;
this.speedCalculator = speedCalculator; // This is new!
}
@kevindoran
kevindoran / Dragon.java
Created June 1, 2013 03:00
Dragon class. This class is used to demonstrate Java Serialization aspects.
public class Dragon implements Serializable {
private static final long serialVersionUID = 1L;
private double wingSpan;
private String name;
public Dragon(double wingSpan, String name) {
// Input checks. For example, insuring wing size is greater than zero.
this.wingSpan = wingSpan;
this.name = name;
@kevindoran
kevindoran / Dragon.java
Created June 1, 2013 02:51
Dragon class with inner speed calculator. This class is used to demonstrate aspects of Java serialization.
public class Dragon implements Serializable {
private static final long serialVersionUID = 1L;
private double wingSpan;
private String name;
private SpeedCalculator speedCalculator = new SpeedCalculator();
public Dragon(double wingSpan, String name) {
// Input checks. For example, insuring wing size is greater than zero.
this.wingSpan = wingSpan;
@kevindoran
kevindoran / PyBluezClient.py
Last active January 30, 2023 19:42
A simple Python script to send messages to a sever over Bluetooth using PyBluez (with Python 2).
"""
A simple Python script to send messages to a sever over Bluetooth
using PyBluez (with Python 2).
"""
import bluetooth
serverMACAddress = '00:1f:e1:dd:08:3d'
port = 3
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
@kevindoran
kevindoran / pyBluezServer.py
Last active November 6, 2022 23:39
A simple Python script to receive messages from a client over Bluetooth using PyBluez (with Python 2).
"""
A simple Python script to receive messages from a client over
Bluetooth using PyBluez (with Python 2).
"""
import bluetooth
hostMACAddress = '00:1f:e1:dd:08:3d' # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters.
port = 3
backlog = 1
@kevindoran
kevindoran / serverDifference.py
Last active December 16, 2015 11:38
Difference between the Bluetooth and Internet client-server applications.
# For the Server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.1.17",50001)) # The Bluetooth MAC Address and RFCOMM port is replaced with an IP Address and a TCP port.
# For the Client
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.1.17",50001))
@kevindoran
kevindoran / socketServer.py
Last active March 23, 2021 18:42
A simple Python script to receive messages from a client over Bluetooth using Python sockets (with Python 3.3 or above).
"""
A simple Python script to receive messages from a client over
Bluetooth using Python sockets (with Python 3.3 or above).
"""
import socket
hostMACAddress = '00:1f:e1:dd:08:3d' # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters.
port = 3 # 3 is an arbitrary choice. However, it must match the port used by the client.
backlog = 1