Skip to content

Instantly share code, notes, and snippets.

View danthemango's full-sized avatar

danthemango danthemango

View GitHub Profile
@danthemango
danthemango / README.md
Last active October 18, 2024 19:05
Detect and send message to your program on Duolingo challenge completed
  • open chrome://extensions/ and turn on "Developer Mode" on the top right
  • install tampermonkey: https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
  • click on the extension, then click "create a new script"
  • in the editor, copy the userscript.js file contents
  • install python, flask, and run server.py
@danthemango
danthemango / capureVideoScreenshot chrome bookmark
Created October 2, 2024 19:05
Create a screenshot of a video using devtools
javascript: function captureVideoScreenshot() { const video = document.querySelector('video'); if (!video) { console.error('No video element found.'); return; } const canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; const ctx = canvas.getContext('2d'); ctx.drawImage(video, 0, 0, canvas.width, canvas.height); const link = document.createElement('a'); link.href = canvas.toDataURL('image/png'); link.download = 'screenshot.png'; link.click();}captureVideoScreenshot();
@danthemango
danthemango / gpu-render.py
Last active October 20, 2024 10:38
enable optix GPU rendering in blender python
import bpy, sys, os
# enable GPU rendering if possible
# use whatever device type is available, in oder of device_type_preferences left-to-right
def set_device_type(device_type_preferences=['OPTIX', 'CUDA', 'CPU']):
prefs = bpy.context.preferences
cycles_prefs = prefs.addons['cycles'].preferences
enabled_devices = []
for device_type_preference in device_type_preferences:
@danthemango
danthemango / ukMap.R
Created November 17, 2023 08:04
British Generic Place Name Mapper
# generic place name maps in great britain (not northern ireland, my dataset didn't include it)
# I used the place name data from https://www.ordnancesurvey.co.uk
# it doesn't include latitude or longitude, rather "geometry_x", "geometry_y" values which correspond
# to the british ordinance survey national grid
# where 'geometry_x' is the number of metres east of the southwest corner of the grid
# and 'geometry_y' is the number of metres north of the southwest corner of the grid
# I am using the sgo library to convert BNG to WGS84
# (note: WGS84 is the standard, google maps location format)
@danthemango
danthemango / keybindings.json
Last active August 28, 2024 19:17
Some keybindings I use, some for vsvim and copilot
// this adds a command to re-run the previous bash command
// asuming you git-bash or another bash terminal open inside of vscode
// update the keybindings json array as follows
[
// run `!!` in terminal (repeats last bash command)
{
"key": "shift+enter",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "!!\r"
@danthemango
danthemango / index.html
Created August 10, 2023 20:28
HTML Canvas boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>canvas</title>
</head>
<body>
<canvas> </canvas>
<script>
@danthemango
danthemango / string2json.mjs
Last active August 10, 2023 20:31
nodejs turn factorio blueprint to json
/*
https://wiki.factorio.com/Blueprint_string_format
turn blueprint string to json
*/
import fs from "fs";
import { unzip } from "zlib";
// returns a flagged argument value, if found
function getFlaggedArg(flag) {
@danthemango
danthemango / string2json.sh
Created July 3, 2023 02:20
Factorio blueprint share string to json
# note: zlib-flate is part of the 'qpdf' package
tail -c +2 factoriostring.txt | base64 -d | zlib-flate -uncompress
@danthemango
danthemango / chrome-bookmark-code
Last active September 2, 2024 20:33
quick javascript function to fetch youtube timestamp from livestream, for pasting into devtools
javascript:(function getURLTime() { const params = (new URL(document.location)).searchParams; const v = params.get('v'); const ytplayer = document.getElementById("movie_player"); const t = Math.round(ytplayer.getCurrentTime()); const newUrl = `https://youtu.be/${v}?t=${t}`; return alert(newUrl); })()
@danthemango
danthemango / dlclip.sh
Last active February 24, 2022 08:40
Bash script to dowload a video section by timestamp via youtube-dl and ffmpeg (works for youtube, twitch, etc.)
#!/bin/bash
function printUsage() {
echo "usage: bash $0 -i <inurl> -ss <starttime> -t <duration> -o <outfile>"
echo ' other args are passed directly to youtube-dl; eg, -r 40K'
}
if [ "$#" -eq 0 ]; then
printUsage
exit