Skip to content

Instantly share code, notes, and snippets.

View petermeissner's full-sized avatar
💻
githubbing

Peter Meissner petermeissner

💻
githubbing
View GitHub Profile
from PIL import Image
import glob
images = glob.glob("*.jpg")
for img in images:
img_obj = Image.open(img)
img_obj.thumbnail(size=(400,400))
img_obj.save(img, optimize=True, quality=65)
def dictkv_in_dictkv(dict_1: dict, dict_2: dict) -> bool:
"""
Function that checks if a set of key-values (expressed as dictionary) can be
found in another set of key-values (expressed as dictionary).
Args:
dict_1 (dict): find those kv (needles)
dict_2 (dict): search within these kv (haystack)
@petermeissner
petermeissner / download.js
Created April 30, 2021 19:08
Download JSON file from webpage
function date(){
var date = new Date();
return date.toISOString().substr(0,10);
}
function download(content, filename, contentType) {
if(!contentType) contentType = 'application/octet-stream';
var a = document.createElement('a');
var blob = new Blob([content], {'type':contentType});
@petermeissner
petermeissner / endless_hit_harmless_key_on_win.vbs
Created April 19, 2021 09:31
script to endlessly 'press' key at certain intervals
Dim objResult
Set objShell = WScript.CreateObject("WScript.Shell")
Do While True
objResult = objShell.sendkeys("{F15}")
Wscript.Sleep (60000)
Loop
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Drawing Points</title>
<script src="js_lib/vue.js"></script>
</head>
<body>
<script type="text/x-template" id="svg_points-template">
@petermeissner
petermeissner / README.md
Last active May 23, 2020 18:46 — forked from thudfactor/README.md
Drag from HTML, Drop to SVG

This demonstrates dragging from HTML to SVG elements, which can be tricky because of the differences between SVG and HTML DOMs. JQueryUI has a nice API for handling drag and drop, including defining the appearance of a dragged object and providing start, drag, and stop events. Unfortunately, JQueryUI's "drop" does not work at all on SVG elements inside the SVG tag, although it does appear to work on the SVG tag itself.

To get over this limitation, we create a custom Drag/Drop manager, and use the start, drag, and stop events for the dragged elements in conjunction with mouseover and mouseout events on the SVG elements to determine whether or not a "drop" has been dropped on a legal SVG element.

#!/usr/bin/python3
# usage:
# shell> python3 python text_to_speech.py -l en -t "Wohooo, it works!" -p
# imports
import argparse
from gtts import gTTS
from playsound import playsound
@petermeissner
petermeissner / is_type_x.js
Created January 5, 2018 09:45
checking for specific type / class in Javascript
// - check type of input
is_type_x = function(object, type){
// go through cases: undefined, object, primitive
if( typeof(object) === "undefined" ){
// undefined cannot be matched
return false;
} else if( typeof(object) === "object" ){
// objects have to be matched against constructor
if( window[type] === undefined ){
@petermeissner
petermeissner / purrr_awesome.R
Last active December 7, 2016 21:03
the most awesome purrr feature?
# capturing failure with default values
library(purrr)
# a faulty function
f <- function(x){
# some nasty error occuring once in a while
if( x %% 2 == 0 ){
@petermeissner
petermeissner / helloworld.r
Last active August 29, 2015 14:21
Hello World
hello_world <- function() {
message(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
"* * * * HELLO WORLD * * * *\n",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
)
}
hello_world()