Skip to content

Instantly share code, notes, and snippets.

@Bahm
Bahm / numbers.tex
Created November 15, 2018 04:30
Generates pages counting from 1 to n
\documentclass[a4paper,landscape]{article}
\usepackage[margin=0pt]{geometry}
\usepackage{fix-cm}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[sfdefault]{cabin}
\pagestyle{empty}
\makeatletter
@Bahm
Bahm / convex_hull_from_image_phaser.py
Created March 20, 2017 11:08
Construct convex hull from image and output it as Phaser polygon (loadPolygon) for P2 physics engine.
#!/usr/bin/env python3
from PIL import Image
from scipy.spatial import ConvexHull
import numpy as np
img = Image.open('image.png')
alphas = list(img.split()[-1].getdata())
region = np.argwhere(alphas)
region = [r[0] for r in region]
@Bahm
Bahm / convex_hull_from_image.py
Last active February 27, 2017 04:15
Construct convex hull from image
#!/usr/bin/env python3
from PIL import Image
from scipy.spatial import ConvexHull
import numpy as np
img = Image.open('image.png')
alphas = list(img.split()[-1].getdata())
region = np.argwhere(alphas)
region = [r[0] for r in region]
@Bahm
Bahm / waitForElmWithTextToExist.js
Created December 23, 2016 05:59
waitForElmWithTextToExist and getElmWithText
function getElmWithText(selector, elmInnerText){
var elms = document.querySelectorAll(selector);
for(var i = 0; i < elms.length; i++)
if (elms[i].innerText !== undefined &&
elms[i].innerText.includes(elmInnerText))
break;
return elms[i];
}
@Bahm
Bahm / mouse-server.py
Last active December 23, 2016 06:01
mouse.py + HTTPServer. 127.0.0.1:8080/?endCoords=100,100&click=true
#!/usr/bin/env python3
import math
from pymouse import PyMouse
from random import randint
from time import sleep
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs
class MouseMovementCalculator:
@Bahm
Bahm / mouse.py
Last active March 16, 2021 16:42
A python 3 version of SRL-6's _humanWindMouse from /lib/core/mouse.simba with modifications. PyMouse installed through PyUserinput: "pip3 install pyuserinput".
#!/usr/bin/env python3
import math
from pymouse import PyMouse
from random import randint
from time import sleep
class MouseMovementCalculator:
def __init__(self, gravity, wind, mouseSpeed, targetError):
self.gravity = gravity
@Bahm
Bahm / mouse.js
Last active May 10, 2020 15:27
A javascript version of SRL-6's _humanWindMouse from /lib/core/mouse.simba with modifications.
// Example:
// var mouseCalc = new MouseMovementCalculator(7, 5, 20, 200);
// var coordsAndDelay = mouseCalc.calcCoordsAndDelay([cursor.x, cursor.y], [destX, destY]);
function MouseMovementCalculator(gravity, wind, mouseSpeed, targetError){
this.gravity = gravity;
this.wind = wind;
this.mouseSpeed = mouseSpeed;
this.targetError = targetError;
}
@Bahm
Bahm / waitForElementToExist.js
Last active December 23, 2016 06:00
waitForElementToExist and waitForElementsToExist
// selector: string CSS selector, e.g., "#comment-section" or "div.comment, #user-id".
// action: function Function to call when an element matches the selector.
function waitForElementToExist(selector, action) {
var elm = document.querySelector(selector);
if(elm !== null)
action(elm);
else
setTimeout(waitForElementToExist.bind(null, selector, action), 100);
}