Skip to content

Instantly share code, notes, and snippets.

View danthemango's full-sized avatar

danthemango danthemango

View GitHub Profile
@danthemango
danthemango / gpu-render.py
Last active January 12, 2024 23:05
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
Created August 31, 2023 17:55
VS Code, run previous terminal command
// 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
[
{
"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 / getURLTime.js
Created February 15, 2022 23:00
quick javascript function to fetch youtube timestamp from livestream, for pasting into devtools
(function getURLTime() {
const params = (new URL(document.location)).searchParams
if(params.has('v')) {
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 newUrl;
}
return document.location;
@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
@danthemango
danthemango / livechatpusher.js
Last active March 13, 2024 00:07
Userscript to keep youtube chat to "live chat" (instead of "top chat")
// ==UserScript==
// @name YouTube Persistent Live Chat
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Try to keep youtube livestream chat in "live chat" or "live chat replay" mode
// @include https://www.youtube.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
@danthemango
danthemango / xkcdnav.js
Last active July 26, 2021 02:53
userscript to navigate XKCD with J and K
// ==UserScript==
// @name XKCD Nav
// @namespace http://tampermonkey.net/
// @version 0.1
// @description move back and forth in xkcd comic with J and K
// @match https://*.xkcd.com/*
// @grant none
// ==/UserScript==
// main
(function() {